

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

# 在 AWS Control Tower 中自动执行任务
<a name="automating-tasks"></a>

许多客户更喜欢在 AWS Control Tower 中自动执行任务，例如账户预置、控制分配和审计。您可以通过调用以下项来设置这些自动操作：
+ [AWS Service Catalog APIs](https://docs.aws.amazon.com//servicecatalog/latest/dg/service-catalog-api-overview.html) 
+ [AWS Organizations APIs](https://docs.aws.amazon.com//organizations/latest/APIReference/Welcome.html)
+ [AWS Control Tower APIs](https://docs.aws.amazon.com//controltower/latest/APIReference/Welcome.html)
+ [C AWS LI](https://docs.aws.amazon.com//cli/latest/reference/servicecatalog/index.html)

[其他信息和链接](related-information.md)页面包含指向许多优秀技术博客文章的链接，可帮助您在 AWS Control Tower 中自动执行任务。以下各部分提供了指向本 *AWS Control Tower 用户指南*中可帮助您自动执行任务的方面的链接。

**自动执行控件任务**

 您可以通过 AWS Control Tower API 自动执行与应用和移除控件（也称为*护栏*）相关的任务。有关详细信息，请参阅 [AWS Control Tower API 参考](https://docs.aws.amazon.com//controltower/latest/APIReference/Welcome.html)。

有关如何使用 AWS Control Tower 执行控制操作的更多信息 APIs，请参阅博客文章 [AWS Control Tower 发布 API，这是针对您的组织单位的预定义控件](https://aws.amazon.com//blogs/mt/aws-control-tower-releases-api-pre-defined-controls-to-your-organizational-units/)。

**自动执行登录区任务**

AWS Control Tower 着陆区 APIs 可帮助您自动执行与着陆区相关的某些任务。有关详细信息，请参阅 [AWS Control Tower API 参考](https://docs.aws.amazon.com//controltower/latest/APIReference/Welcome.html)。

**自动执行 OU 注册**

AWS Control Tower 基准 APIs 可帮助您自动执行某些任务，例如注册 OU。有关详细信息，请参阅 [AWS Control Tower API 参考](https://docs.aws.amazon.com//controltower/latest/APIReference/Welcome.html)。

**自动关闭账户**

您可以使用 AWS Organizations API 自动关闭 AWS Control Tower 成员账户。有关更多信息，请参阅 [通过关闭 AWS Control Tower 成员账户 AWS Organizations](delete-account.md#close-account-with-orgs-api)。

**自动预置和更新账户**

*AWS Control Tower 账户工厂定制 (AFC)* 可帮助您通过 AWS Control Tower 控制台创建账户，并使用我们称之为蓝图的自定义 CloudFormation 模板。从某种意义上说，这一过程是自动化的，即在设置单个蓝图后，您可以重复创建新账户和更新账户，而无需维护管道。

*适用于 Terraform 的 AWS Control Tower Account Factor* y (AFT) 遵循一种 GitOps 模型，在 AWS Control Tower 中自动执行账户配置和账户更新流程。有关更多信息，请参阅 [利用 AWS Control Tower Account Factory for Terraform（AFT）预置账户](taf-account-provisioning.md)。

*AWS Control Tower* (cfcT) 的自定义可帮助您自定义 AWS Control Tower 着陆区，并与 AWS 最佳实践保持一致。通过 AWS CloudFormation 模板、服务控制策略 (SCPs) 和资源控制策略 (RCPs) 实现自定义。有关更多信息，请参阅 [Customizations for AWS Control Tower（CfCT）概述](cfct-overview.md)。

有关自动账户预置的更多信息和视频，请参阅 [Walkthrough: Automated account provisioning in AWS Control Tower](https://docs.aws.amazon.com//controltower/latest/userguide/automated-provisioning-walkthrough.html) 和 [Automated provisioning with IAM roles](https://docs.aws.amazon.com//controltower/latest/userguide/roles-how.html#automated-provisioning)。

另请参阅 [Update accounts by script](https://docs.aws.amazon.com//controltower/latest/userguide/configuration-updates.html#update-accounts-by-script)。

**账户的编程式审计**

有关以编程方式审计账户的更多信息，请参阅 [Programmatic roles and trust relationships for the AWS Control Tower audit account](https://docs.aws.amazon.com//controltower/latest/userguide/roles-how.html#stacksets-and-roles)。

**自动执行其他任务**

有关如何使用自动请求方法增加某些 AWS Control Tower 服务配额的信息，请观看此视频：[Automate Service Limit Increases](https://www.youtube.com/watch?v=3WUShZ4lZGE)。

有关介绍自动化和集成使用案例的技术博客，请参阅 [Automation and integration](https://docs.aws.amazon.com/controltower/latest/userguide/related-information.html#automation-and-integration)。

有两个开源示例 GitHub 可帮助您完成某些与安全相关的自动化任务。
+ 名为 [aws-control-tower-org-setup-sample 的示例](https://github.com/aws-samples/aws-control-tower-org-setup-sample)显示了如何自动将审核帐户设置为安全相关服务的委托管理员。
+ 名为 [aws-control-tower-account-](https://github.com/aws-samples/aws-control-tower-account-setup-using-step-functions) 的示例setup-using-step-functions显示了在配置和配置新账户时如何使用 Step Functions 自动执行安全最佳实践。此示例包括将委托人添加到组织共享的 AWS Service Catalog 投资组合中，以及将组织范围内的 AWS IAM Identity Center 群组自动关联到新账户。它还说明了如何删除每个区域中的默认 VPC。

*AWS Security Reference Architecture* 包括用于自动执行与 AWS Control Tower 相关的任务的代码示例。有关更多信息，请参阅 “[AWS 规范性指南” 页面](https://docs.aws.amazon.com//prescriptive-guidance/latest/security-reference-architecture/welcome.html)和[相关的 GitHub 存储库](https://github.com/aws-samples/aws-security-reference-architecture-examples/tree/main/aws_sra_examples)。

有关将 AWS Control Tower 与 AWS CloudShell一项便于在 AWS CLI 中工作的 AWS 服务结合使用的信息，请参阅[AWS CloudShell 和 AWS CLI](https://docs.aws.amazon.com//controltower/latest/userguide/using-aws-with-cloudshell.html)。

由于 AWS Control Tower 是的编排层 AWS Organizations，因此可以通过 APIs 和 AWS CLI 获得许多其他 AWS 服务。有关更多信息，请参阅[相关 AWS 服务](https://docs.aws.amazon.com//controltower/latest/userguide/related-information.html#related-aws-services)。

# 用于AWS CloudShell与之配合AWS Control Tower
<a name="using-aws-with-cloudshell"></a>

AWS CloudShell是一项便于在AWS CLI 中工作的AWS服务 — 它是一个基于浏览器、经过预先验证的 shell，您可以直接从启动。AWS 管理控制台无需下载或安装命令行工具。您可以通过首选外壳（Bash PowerShell 或 Z shell）为和其他AWS服务运行AWS CLI命令。AWS Control Tower

当您[AWS CloudShell从启动](https://docs.aws.amazon.com/cloudshell/latest/userguide/working-with-cloudshell.html#launch-options)时AWS 管理控制台，用于登录控制台的AWS凭据将在新的 shell 会话中可用。当你与其他AWS服务交互时，你可以跳过输入配置凭证，而你将使用预先安装在外壳程序计算环境中的AWS CLI版本 2。你已通过预先身份验证。AWS Control TowerAWS CloudShell

## 获取 IAM 权限AWS CloudShell
<a name="cloudshell-permissions"></a>

AWS Identity and Access Management提供访问管理资源，允许管理员向 IAM 用户和 IAM Identity Center 用户授予访问权限AWS CloudShell。

管理员向用户授予访问权限的最快方法是通过AWS托管策略。[AWS托管式策略](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_managed-vs-inline.html#aws-managed-policies)是由AWS创建和管理的独立策略。以下的AWS托管策略 CloudShell 可以附加到 IAM 身份：
+ `AWSCloudShellFullAccess`：授予使用权限，并AWS CloudShell具有对所有功能的完全访问权限。

 如果您想限制 IAM 用户或 IAM Identity Center 用户可以执行的操作范围AWS CloudShell，则可以创建使用`AWSCloudShellFullAccess`托管策略作为模板的自定义策略。有关限制中可供用户执行的操作的更多信息 CloudShell，请参阅*AWS CloudShell用户指南*中的[使用 IAM 策略管理AWS CloudShell访问和使用情况](https://docs.aws.amazon.com/cloudshell/latest/userguide/sec-auth-with-identities.html)。

**注意**  
您的 IAM 身份还需要一个策略来授予对AWS Control Tower进行调用的权限。有关更多信息，请参阅[使用AWS Control Tower控制台所需的权限](https://docs.aws.amazon.com//controltower/latest/userguide/access-control-managing-permissions.html#additional-console-required-permissions)。

### 启动AWS CloudShell
<a name="launch-cloudshell"></a>

从中AWS 管理控制台，您可以 CloudShell 通过选择导航栏上的以下可用选项来启动：
+  选择图 CloudShell 标。
+ 开始在搜索框中输入 “cloudshell”，然后选择相应 CloudShell选项。

现在你已经开始了 CloudShell，你可以输入任何你需要使用的AWS CLI命令AWS Control Tower。例如，您可以检查自己的AWS Config状态。

# AWS Control Tower通过以下方式与之互动AWS CloudShell
<a name="cshell-examples"></a>

AWS CloudShell从启动后AWS 管理控制台，您可以立即开始AWS Control Tower从命令行界面与之交互。AWS CLI命令在中以标准方式工作 CloudShell。

**注意**  
AWS CLI在中使用时AWS CloudShell，您无需下载或安装任何其他资源。您已经在 Shell 中进行了身份验证，因此在进行调用之前也无需配置凭证。<a name="cloudshell-and-controltower"></a>

# AWS CloudShell用于帮助设置AWS Control Tower
<a name="cloudshell-and-controltower"></a>

在执行这些程序之前，除非另有说明，否则您必须登录到着陆区域的主区域，并且必须以 IAM Identity Center 用户或对包含您的着陆区的管理账户具有管理权限的 IAM 用户身份登录。AWS 管理控制台

1. 在开始配置 landing zone 之前，您可以通过以下方式在中AWS CloudShell使用AWS Config CLI 命令来确定配置记录器和传送渠道AWS Control Tower的状态。

   **示例：查看您的AWS Config状态**

**查看命令：**
   + `aws configservice describe-delivery-channels`
   + `aws configservice describe-delivery-channel-status`
   + `aws configservice describe-configuration-recorders`
   + 正常的响应类似于 `"name": "default"`

1. 如果您有现有的AWS Config录音机或传送渠道，需要在设置 landing z AWS Control Tower one 之前将其删除，则可以输入以下命令：

   **示例：管理您先前存在AWS Config的资源**

**删除命令：**
   + `aws configservice stop-configuration-recorder --configuration-recorder-name NAME-FROM-DESCRIBE-OUTPUT`
   + `aws configservice delete-delivery-channel --delivery-channel-name NAME-FROM-DESCRIBE-OUTPUT`
   + `aws configservice delete-configuration-recorder --configuration-recorder-name NAME-FROM-DESCRIBE-OUTPUT`
**重要**  
请勿删除的AWS Control Tower资源AWS Config。这些资源的丢失可能导致AWS Control Tower进入不一致的状态。

**有关更多信息，请参阅AWS Config文档**
   +  [管理配置记录器 (AWS CLI)](https://docs.aws.amazon.com//config/latest/developerguide/stop-start-recorder.html#managing-recorder_cli)
   +   [管理传输通道](https://docs.aws.amazon.com//config/latest/developerguide/manage-delivery-channel.html)

1. 此示例显示了为启用或禁用可信AWS CloudShell访问而输入的AWS CLI 命令AWS Organizations。因为AWS Control Tower您不需要为启用或禁用可信访问权限AWS Organizations，这只是一个示例。但是，如果您要在中自动执行或自定义操作，则可能需要启用或禁用其他AWS服务的可信访问权限。AWS Control Tower

**示例：启用或禁用可信服务访问**
   + `aws organizations enable-aws-service-access`
   + `aws organizations disable-aws-service-access`<a name="cloudshell-and-s3"></a>

# 示例：使用创建 Amazon S3 存储桶AWS CloudShell
<a name="cloudshell-and-s3"></a>

在以下示例中，您可以使用AWS CloudShell创建 Amazon S3 存储桶，然后使用**PutObject**方法将代码文件作为对象添加到该存储桶中。

1. 要在指定AWS区域创建存储桶，请在命令行中输入以下 CloudShell 命令：

   ```
   aws s3api create-bucket --bucket insert-unique-bucket-name-here --region us-east-1
   ```

   如果调用成功，命令行将显示来自服务的响应，输出与以下类似：

   ```
   {
       "Location": "/insert-unique-bucket-name-here"
   }
   ```
**注意**  
如果您不遵守[命名存储桶的规则](https://docs.aws.amazon.com/AmazonS3/latest/userguide/BucketRestrictions.html#bucketnamingrules)（例如，仅使用小写字母），则会显示以下错误：调用 CreateBucket 操作时出现错误 (InvalidBucketName)：指定的存储桶无效。

1. 要上传文件并将其作为对象添加到刚创建的存储桶，请调用 **PutObject** 方法：

   ```
   aws s3api put-object --bucket insert-unique-bucket-name-here --key add_prog --body add_prog.py
   ```

   将对象成功上传到 Amazon S3 存储桶后，命令行将显示来自服务的响应，类似于以下输出：

   ```
   {
              "ETag": "\"ab123c1:w:wad4a567d8bfd9a1234ebeea56\""}
   ```

   `ETag` 是已存储对象的哈希值。该值可用于[检查上传到 Amazon S3 的对象的完整性](https://aws.amazon.com/premiumsupport/knowledge-center/data-integrity-s3/)。

# 使用创建 AWS Control Tower 资源 AWS CloudFormation
<a name="creating-resources-with-cloudformation"></a>

AWS Control Tower 与一项服务集成 AWS CloudFormation，该服务可帮助您对 AWS 资源进行建模和设置，从而减少创建和管理资源和基础架构所花费的时间。您可以创建一个描述所需的所有 AWS 资源（例如控件资源）`AWS::ControlTower::EnabledControl`的模板。 CloudFormation 为您配置和配置这些资源。

使用时 CloudFormation，您可以重复使用模板来一致且重复地设置 AWS Control Tower 资源。只需描述一次您的资源，然后在多个 AWS 账户 区域中一遍又一遍地配置相同的资源。

## AWS Control Tower 和 CloudFormation 模板
<a name="working-with-templates"></a>

要为和相关服务配置 AWS Control Tower 和配置资源，必须了解[CloudFormation 模板](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-guide.html)。模板是 JSON 或 YAML 格式的文本文件。这些模板描述了您要在 CloudFormation 堆栈中配置的资源。如果你不熟悉 JSON 或 YAML，可以使用 D CloudFormation esigner 来帮助你开始使用 CloudFormation 模板。有关更多信息，请参阅《AWS CloudFormation 用户指南》**中的[什么是 CloudFormation Designer？](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/working-with-templates-cfn-designer.html)。

AWS Control Tower 支持在中创建`AWS::ControlTower::EnabledControl`（控制资源）、`AWS::ControlTower::LandingZone`（着陆区）和`AWS::ControlTower::EnabledBaseline`（基线）。 CloudFormation有关更多信息（包括这些资源类型的 JSON 和 YAML 模板示例），请参阅《AWS CloudFormation 用户指南》**中的 [AWS Control Tower](https://docs.aws.amazon.com//AWSCloudFormation/latest/UserGuide/AWS_ControlTower.html)。

**注意**  
中`EnableControl`和更`DisableControl`新的限制 AWS Control Tower 为 100 个并发操作。

要查看 CLI 和控制台的一些 AWS Control Tower 示例，请参阅[使用启用控件 CloudFormation](https://docs.aws.amazon.com//controltower/latest/userguide/enable-controls.html)。

## 了解更多关于 CloudFormation
<a name="learn-more-cloudformation"></a>

要了解更多信息 CloudFormation，请参阅以下资源：
+ [AWS CloudFormation](https://aws.amazon.com/cloudformation/)
+ [AWS CloudFormation 用户指南](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html)
+ [CloudFormation API 参考](https://docs.aws.amazon.com/AWSCloudFormation/latest/APIReference/Welcome.html)
+ [AWS CloudFormation 命令行界面用户指南](https://docs.aws.amazon.com/cloudformation-cli/latest/userguide/what-is-cloudformation-cli.html)