使用设置聚合器 AWS Command Line Interface - AWS Config

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

使用设置聚合器 AWS Command Line Interface

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

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

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

使用个人账户添加聚合器

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

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

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

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

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

    • 您也可以上传以逗号分隔 AWS 账户 的 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 } }

使用 AWS Organizations 添加聚合器

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

注意

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

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

  2. 如果尚未为 AWS 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),以便在创建聚合器时使用。 AWS 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 } }

注册委派管理员

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

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

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

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

    aws organizations enable-aws-service-access --service-principal=config-multiaccountsetup.amazonaws.com
  4. 输入以下命令以授权管理员的身份为您的组织启用服务访问权限,以便在整个组织中聚合 AWS 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. 接下来,输入以下命令以注册一个成员账户作为 AWS 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

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