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

2 分钟阅读
0

当我创建 AWS Config 记录器时,收到 MaxNumberOfConfigurationRecordersExceededException 错误。

简短描述

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

解决方法

**注意:**如果您在运行 AWS CLI 命令时收到错误,请参阅 AWS CLI 错误故障排除。此外,请确保您使用的是最新版本的 AWS CLI

要解决 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,识别并删除配置记录器

完成以下任务。

识别现有的配置记录器名称

要识别特定区域中的现有配置记录器,请运行 describe-configuration-recorders 命令:

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

**注意:**将 RegionID 替换为您的区域。

查看输出。现有的配置记录器名称列在输出中的 name(名称)旁边。

删除现有的配置记录器

要删除现有的配置记录器,请运行 delete-configuration-recorder 命令:

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

**注意:**将 RecorderName 替换为您的配置记录器的名称,将 RegionID 替换为您的区域 ID。成功删除记录器后,delete-configuration-recorder 命令不会返回输出。

使用 API 调用启动和停止记录器

要启动配置记录器,请运行以下命令:

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

**注意:**将 RecorderName 替换为您的配置记录器的名称。

要停止配置记录器,请运行以下命令:

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

**注意:**将 RecorderName 替换为您的配置记录器的名称。

对于 CloudFormation,识别并删除配置记录器

如果您使用 CloudFormation StackSet 模板打开 AWS Config,请完成以下任务以识别并删除配置记录器。

要编写代码逻辑来识别并删除配置记录器,请使用 AWS Lambda 支持的自定义资源执行以下操作:

删除配置记录器后,您可以使用自定义资源的 cfn-response 模块来创建新的配置记录器。然后,您可以运行 StartConfigurationRecorder API 来启动记录器。

相关信息

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

AWS 官方
AWS 官方已更新 24 天前