在创建 AWS Config 配置记录器时,为什么我会收到 MaxNumberOfConfigurationRecordersExceededException 错误?

2 分钟阅读
0

当我尝试创建一个 AWS Config 配置记录器时,我收到了 MaxNumberOfConfigurationRecordersExceededException 错误。该如何排查此问题?

简短描述

AWS Config 使用配置记录器来记录资源配置中的更改。AWS Config 目前只允许一个账户在每个区域拥有一个配置记录器。MaxNumberOfConfigurationRecordersExceededException 错误表示您无法创建新的配置记录器,因为您的账户已在该区域存在一个配置记录器。无论记录器是使用 AWS 管理控制台、AWS 命令行界面 (AWS CLI) 还是 AWS CloudFormation 创建的,都会出现此错误。

解决方法

要解决 MaxNumberOfConfigurationRecordersExceededException 错误并创建新的配置记录器,您必须找到已经存在的配置记录器并将其删除。

注意:无法从控制台删除配置记录器。必须以编程方式执行删除操作。

首先,验证是否具有正确的 AWS Identity and Access Management (IAM) 权限来运行所需的命令。然后,您可以使用 AWS CLI 或 CloudFormation 找到并删除已经存在的配置记录器。

IAM 权限

要描述和删除配置记录器,请添加以下 IAM 权限:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": [
                "config:DescribeConfigurationRecorders",
                "config:DeleteConfigurationRecorder"
            ],
            "Resource": "*"
        }
    ]
}

要启动和停止配置记录器,请添加以下 IAM 权限:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": [
                "config:PutConfigurationRecorder",
                "iam:PassRole",
                "config:DescribeConfigurationRecorders",
                "config:StopConfigurationRecorder",
                "config:StartConfigurationRecorder",
                "config:DeleteConfigurationRecorder"
            ],
            "Resource": "*"
        }
    ]
}

找到并删除配置记录器 (AWS CLI)

注意:如果在运行 AWS CLI 命令时遇到错误,请确保您使用的是最新版本的 AWS CLI

找到已经存在的配置记录器的名称

运行以下命令找到特定区域中已经存在的配置记录器。请将 RegionID 替换为您的 AWS 区域

$aws configservice describe-configuration-recorders --region RegionID

查看输出。已经存在的配置记录器的名称在输出的 **“name”**旁列出。

删除已经存在的配置记录器

运行以下命令删除已经存在的配置记录器。将 RecorderNameRegionID 替换为您的值。

$aws configservice delete-configuration-recorder --configuration-recorder-name RecorderName --region RegionID

注意:成功删除记录器后,delete-configuration-recorder 命令将不会返回输出。

用于启动和停止记录器的 API 调用

如果需要启动或停止配置记录器,则可以使用 API 调用。

运行以下命令启动配置记录器。将 RecorderName 替换为您的配置记录器的名称。

$aws configservice start-configuration-recorder --configuration-recorder-name RecorderName

运行以下命令停止配置记录器。将 RecorderName 替换为您的配置记录器的名称。

$aws configservice stop-configuration-recorder --configuration-recorder-name RecorderName

找到并删除配置记录器 (CloudFormation)

如果您使用 CloudFormation StackSets 模板启用了 AWS Config,请按照本节中的指导来找到并删除配置记录器。

您可以使用 AWS Lambda 支持的自定义资源来编写代码逻辑,从而找到并删除配置记录器。

删除配置记录器后,您可以对自定义资源使用 cfn-response module,以继续创建新的配置记录器。

创建新的配置记录器后,您可以运行 StartConfigurationRecorder API 来启动记录器。


相关信息

describe-configuration-recorders

delete-configuration-recorder

CloudFormation custom resource creation with Python, AWS Lambda, and crhelper

AWS 官方
AWS 官方已更新 3 年前