使用设置聚合器 Amazon Command Line Interface - Amazon Config
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

使用设置聚合器 Amazon Command Line Interface

您可以使用 Amazon Command Line Interface (Amazon CLI) 创建、查看、更新和删除 Amazon Config 聚合器数据。

Amazon CLI 是用于管理您的 Amazon 服务的统一工具。只需下载和配置一个工具,您就可以从命令行控制多项 Amazon 服务,并使用脚本自动执行这些服务。有关 Amazon CLI 和 Amazon CLI 工具安装说明的更多信息,请参阅《Amazon Command Line Interface 用户指南》中的以下内容。

如有必要,aws configure请输入配置 Amazon CLI 为使用有聚合器的 Amazon 区域。

使用个人账户添加聚合器

  1. 打开命令提示符或终端窗口。

  2. 输入以下命令以创建一个名为 MyAggregator 的聚合器。

    aws configservice put-configuration-aggregator --configuration-aggregator-name MyAggregator --account-aggregation-sources "[{\"AccountIds\": [\"AccountID1\",\"AccountID2\",\"AccountID3\"],\"AllAwsRegions\": true}]"

    对于 account-aggregation-sources,输入以下内容之一。

    • 要聚合其数据的 Amazon Web Services 账户 ID 的逗号分隔列表。用方括号将账户 ID 括起来,并确保对引号进行转义 (例如,"[{\"AccountIds\": [\"AccountID1\",\"AccountID2\",\"AccountID3\"],\"AllAwsRegions\": true}]")。

    • 您也可以上传以逗号分隔 Amazon Web Services 账户 的 ID 的 JSON 文件。上传文件使用以下语法:--account-aggregation-sources MyFilePath/MyFile.json

      JSON 文件必须为以下格式:

    [ { "AccountIds": [ "AccountID1", "AccountID2", "AccountID3" ], "AllAwsRegions": true } ]
  3. 按 Enter 执行命令。

    您应该可以看到类似于如下所示的输出内容:

    { "ConfigurationAggregator": { "ConfigurationAggregatorArn": "arn:aws:config:Region:AccountID:config-aggregator/config-aggregator-floqpus3", "CreationTime": 1517942461.442, "ConfigurationAggregatorName": "MyAggregator", "AccountAggregationSources": [ { "AllAwsRegions": true, "AccountIds": [ "AccountID1", "AccountID2", "AccountID3" ] } ], "LastUpdatedTime": 1517942461.442 } }

使用 Amazon Organizations 添加聚合器

在开始本过程之前,您必须先登录到管理账户或注册的委派管理员,并且所有功能都必须在组织中处于启用状态。

注意

在委派管理员创建聚合器之前,请确保管理账户使用以下两个 Amazon Config 服务主体名称(config.amazonaws.comconfig-multiaccountsetup.amazonaws.com)注册委派管理员。要注册委派管理员,请参阅注册委派管理员

  1. 打开命令提示符或终端窗口。

  2. 如果尚未为 Amazon Config 聚合器创建 IAM 角色,请输入以下命令:

    aws iam create-role --role-name OrgConfigRole --assume-role-policy-document "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Sid\":\"\",\"Effect\":\"Allow\",\"Principal\":{\"Service\":\"config.amazonaws.com\"},\"Action\":\"sts:AssumeRole\"}]}" --description "Role for organizational AWS Config aggregator"
    注意

    复制此 IAM 角色中的亚马逊资源名称 (ARN),以便在创建聚合器时使用。 Amazon Config 您可以在响应对象上找到 ARN。

  3. 如果尚未将策略附加到您的 IAM 角色,请附加AWSConfigRoleForOrganizations托管策略或输入以下命令:

    aws iam create-policy --policy-name OrgConfigPolicy --policy-document '{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["organizations:ListAccounts","organizations:DescribeOrganization","organizations:ListAWSServiceAccessForOrganization","organizations:ListDelegatedAdministrators"],"Resource":"*"}]}'
  4. 输入以下命令以创建一个名为 MyAggregator 的聚合器。

    aws configservice put-configuration-aggregator --configuration-aggregator-name MyAggregator --organization-aggregation-source "{\"RoleArn\": \"Complete-Arn\",\"AllAwsRegions\": true}"
  5. 按 Enter 执行命令。

    您应该可以看到类似于如下所示的输出内容:

    { "ConfigurationAggregator": { "ConfigurationAggregatorArn": "arn:aws:config:Region:AccountID:config-aggregator/config-aggregator-floqpus3", "CreationTime": 1517942461.442, "ConfigurationAggregatorName": "MyAggregator", "OrganizationAggregationSource": { "AllAwsRegions": true, "RoleArn": "arn:aws:iam::account-of-role-to-assume:role/name-of-role" }, "LastUpdatedTime": 1517942461.442 } }

注册委派管理员

委派管理员是指给定 Amazon 组织内被授予特定 Amazon 服务的额外管理权限的账户。

  1. 使用管理账户凭证登录。

  2. 打开命令提示符或终端窗口。

  3. 输入以下命令以授权管理员的身份为组织启用服务访问权限,以便在整个组织中部署和管理 Amazon Config 规则和一致性包:

    aws organizations enable-aws-service-access --service-principal=config-multiaccountsetup.amazonaws.com
  4. 输入以下命令以授权管理员的身份为您的组织启用服务访问权限,以便在整个组织中聚合 Amazon Config 数据:

    aws organizations enable-aws-service-access --service-principal=config.amazonaws.com
  5. 要检查启用服务访问权限是否已完成,请输入以下命令并按 Enter 执行此命令。

    aws organizations list-aws-service-access-for-organization

    您应该可以看到类似于如下所示的输出内容:

    { "EnabledServicePrincipals": [ { "ServicePrincipal": [ "config.amazonaws.com", "config-multiaccountsetup.amazonaws.com" ], "DateEnabled": 1607020860.881 } ] }
  6. 接下来,输入以下命令以注册一个成员账户作为 Amazon Config的委派管理员。

    aws organizations register-delegated-administrator --service-principal=config-multiaccountsetup.amazonaws.com --account-id MemberAccountID

    以及

    aws organizations register-delegated-administrator --service-principal=config.amazonaws.com --account-id MemberAccountID
  7. 要检查委派管理员注册是否已完成,请从管理账户中输入以下命令,然后按 Enter 键执行该命令。

    aws organizations list-delegated-administrators --service-principal=config-multiaccountsetup.amazonaws.com

    以及

    aws organizations list-delegated-administrators --service-principal=config.amazonaws.com

    您应该可以看到类似于如下所示的输出内容:

    { "DelegatedAdministrators": [ { "Id": "MemberAccountID", "Arn": "arn:aws:organizations::MemberAccountID:account/o-c7esubdi38/MemberAccountID", "Email": "name@amazon.com", "Name": "name", "Status": "ACTIVE", "JoinedMethod": "INVITED", "JoinedTimestamp": 1604867734.48, "DelegationEnabledDate": 1607020986.801 } ] }

查看聚合器

  1. 输入以下 命令:

    aws configservice describe-configuration-aggregators
  2. 根据您的源账户,您应该看到类似于以下内容的输出:

    对于个人账户

    { "ConfigurationAggregators": [ { "ConfigurationAggregatorArn": "arn:aws:config:Region:AccountID:config-aggregator/config-aggregator-floqpus3", "CreationTime": 1517942461.442, "ConfigurationAggregatorName": "MyAggregator", "AccountAggregationSources": [ { "AllAwsRegions": true, "AccountIds": [ "AccountID1", "AccountID2", "AccountID3" ] } ], "LastUpdatedTime": 1517942461.455 } ] }

    对于组织

    { "ConfigurationAggregator": { "ConfigurationAggregatorArn": "arn:aws:config:Region:AccountID:config-aggregator/config-aggregator-floqpus3", "CreationTime": 1517942461.442, "ConfigurationAggregatorName": "MyAggregator", "OrganizationAggregationSource": { "AllAwsRegions": true, "RoleArn": "arn:aws:iam::account-of-role-to-assume:role/name-of-role" }, "LastUpdatedTime": 1517942461.442 } }

编辑聚合器

  1. 您可以使用 put-configuration-aggregator 命令来更新或编辑配置聚合器。

    输入以下命令以向 MyAggregator 添加新的账户 ID:

    aws configservice put-configuration-aggregator --configuration-aggregator-name MyAggregator --account-aggregation-sources "[{\"AccountIds\": [\"AccountID1\",\"AccountID2\",\"AccountID3\"],\"AllAwsRegions\": true}]"
  2. 根据您的源账户,您应该看到类似于以下内容的输出:

    对于个人账户

    { "ConfigurationAggregator": { "ConfigurationAggregatorArn": "arn:aws:config:Region:AccountID:config-aggregator/config-aggregator-xz2upuu6", "CreationTime": 1517952090.769, "ConfigurationAggregatorName": "MyAggregator", "AccountAggregationSources": [ { "AllAwsRegions": true, "AccountIds": [ "AccountID1", "AccountID2", "AccountID3", "AccountID4" ] } ], "LastUpdatedTime": 1517952566.445 } }

    对于组织

    { "ConfigurationAggregator": { "ConfigurationAggregatorArn": "arn:aws:config:Region:AccountID:config-aggregator/config-aggregator-floqpus3", "CreationTime": 1517942461.442, "ConfigurationAggregatorName": "MyAggregator", "OrganizationAggregationSource": { "AllAwsRegions": true, "RoleArn": "arn:aws:iam::account-of-role-to-assume:role/name-of-role" }, "LastUpdatedTime": 1517942461.442 } }

删除聚合器

输入以下 命令:

aws configservice delete-configuration-aggregator --configuration-aggregator-name MyAggregator

如果成功,则命令会执行,而没有附加输出。