通过 AWS CLI 使用客户管理的配置记录器启动 AWS Config
您可以通过创建客户管理的配置记录器来启动。AWS Config要使用 AWS CLI 创建客户管理的配置记录器,请使用以下命令:put-configuration-recorder、put-delivery-channel 和 start-configuration-recorder。
put-configuration-recorder命令可创建客户管理的配置记录器。put-delivery-channel命令可创建传输通道,AWS Config 通过该通道将配置信息传输到 S3 存储桶和 SNS 主题。start-configuration-recorder将启动客户管理的配置记录器。客户管理的配置记录器将开始记录您指定的资源类型的配置更改。
主题
注意事项
S3 存储桶、SNS 主题和 IAM 角色为必填项
要创建客户管理的配置记录器,您需要创建一个 S3 存储桶、一个 SNS 主题和一个具有附加策略的 IAM 角色作为先决条件。要设置 AWS Config 的先决条件,请参阅先决条件。
每个区域的每个账户配有一个客户管理的配置记录器
每个 AWS 区域每个 AWS 账户只能有一个客户管理的配置记录器。
每个区域的每个账户配有一个传输通道
每个 AWS 区域每个 AWS 账户只能有一个传输通道区域。
策略与合规结果
IAM 策略和 AWS Organizations 中管理的其他策略可能会影响 AWS Config 是否有权记录资源的配置更改。此外,规则会直接评估资源的配置,且执行评估时不会考虑这些策略。确保现行策略与您打算使用 AWS Config 的方式保持一致。
步骤 1:运行 put-configuration-recorder 命令
使用 put-configuration-recorder 命令创建客户管理的配置记录器:
此命令使用 --configuration-recorder 和 ---recording-group 字段。
$ aws configservice put-configuration-recorder \ --configuration-recorderfile://configurationRecorder.json\ --recording-groupfile://recordingGroup.json
configuration-recorder 字段
configurationRecorder.json 文件指定配置记录器的 name 和 roleArn 以及默认记录频率(recordingMode)。您也可以使用此字段来覆盖特定资源类型的记录频率。
{ "name": "default", "roleARN": "arn:aws:iam::123456789012:role/config-role", "recordingMode": { "recordingFrequency":CONTINUOUSorDAILY, "recordingModeOverrides": [ { "description": "Description you provide for the override", "recordingFrequency":CONTINUOUSorDAILY, "resourceTypes": [Comma-separated list of resource types to include in the override] } ] } }
recording-group 字段
recordingGroup.json 文件指定要记录哪些资源类型。
{ "allSupported":boolean, "exclusionByResourceTypes": { "resourceTypes": [Comma-separated list of resource types to exclude] }, "includeGlobalResourceTypes":boolean, "recordingStrategy": { "useOnly": "Recording strategy for the configuration recorder" }, "resourceTypes": [Comma-separated list of resource types to include] }
有关这些字段的更多信息,请参阅《AWS CLI 命令参考》中的 put-configuration-recorder
步骤 2:运行 put-delivery-channel 命令
使用 put-delivery-channel 命令创建传输通道:
此命令使用 --delivery-channel 字段。
$ aws configservice put-delivery-channel --delivery-channel file://deliveryChannel.json
delivery-channel 字段
deliveryChannel.json 文件指定以下内容:
传输通道的
names3BucketName:AWS Config 发送配置快照的地方。snsTopicARN:AWS Config 发送通知的地点configSnapshotDeliveryProperties:用于设置 AWS Config 传输配置快照的频率以及它为定期规则调用评估的频率。
{ "name": "default", "s3BucketName": "config-bucket-123456789012", "snsTopicARN": "arn:aws:sns:us-east-1:123456789012:config-topic", "configSnapshotDeliveryProperties": { "deliveryFrequency": "Twelve_Hours" } }
有关这些字段的更多信息,请参阅《AWS CLI 命令参考》中的 put-delivery-channel
步骤 3:运行 start-configuration-recorder 命令
使用 start-configuration-recorder 命令启动 AWS Config:
$ aws configservice start-configuration-recorder --configuration-recorder-nameconfigRecorderName
有关这些字段的更多信息,请参阅《AWS CLI 命令参考》中的 start-configuration-recorder