為什麼我在建立 AWS Config 組態記錄器時收到 MaxNumberOfConfigurationRecordersExceededException 錯誤?

2 分的閱讀內容
0

當我嘗試建立 AWS Config 組態記錄器時,收到 MaxNumberOfConfigurationRecordersExceededException 錯誤。如何對此問題進行疑難排解?

簡短描述

AWS Config 使用組態記錄器記錄資源組態中的變更。AWS Config 目前只允許帳戶中的每個區域有一個組態記錄器。MaxNumberOfConfigurationRecordersExceededException 錯誤表示您無法建立新的組態記錄器,因為區域的帳戶中已有一個組態記錄器。無論記錄器是使用 AWS 管理主控台、AWS Command Line Interface (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

識別現有的組態記錄器名稱

執行下列命令以識別特定區域中現有的組態記錄器。用您的 AWS 區域取代 RegionID

$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 StackSet template 啟用 AWS Config,請遵循本節中的指引來識別和刪除組態記錄器。

您可以使用 AWS Lambda 支援的自訂資源撰寫代碼邏輯,以識別和刪除組態記錄器。

刪除組態記錄器之後,您可以對自訂資源使用 cfn-response 模組以繼續建立新的組態記錄器。

建立新的組態記錄器之後,您可以執行 StartConfigurationRecorder API 來啟動記錄器。


相關資訊

describe-configuration-recorders

delete-configuration-recorder

使用 Python、AWS Lambda 和 crhelper 建立 CloudFormation 自訂資源

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