

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

# 使用自动设置区域间对等互连 AWS Transit Gateway
<a name="automate-the-setup-of-inter-region-peering-with-aws-transit-gateway"></a>

*Ram Kandaswamy，Amazon Web Services*

## Summary
<a name="automate-the-setup-of-inter-region-peering-with-aws-transit-gateway-summary"></a>

[AWS Transit Gateway](https://docs.aws.amazon.com/vpc/latest/tgw/what-is-transit-gateway.html)通过中央集线器连接虚拟私有云 (VPCs) 和本地网络。Transit Gateway 流量不会通过公共互联网，从而减少了威胁载体，例如常见漏洞利用和分布式拒绝服务攻击。DDo

如果您需要在两个或多个公交网关之间进行通信 AWS 区域，则可以使用区域间 Transit Gateway 对等互连在不同区域的公交网关之间建立对等连接。但是，使用 Transit Gateway 手动配置区域间对等互连可能既复杂又耗时。此模式为使用基础设施即代码 (IaC) 设置对等互连提供了指导。如果您必须重复配置多个区域以及 AWS 账户 多区域组织设置，则可以使用这种方法。

此模式在 Amazon CloudWatch Logs 中设置了一个包含 AWS Step Functions [工作流程](https://docs.aws.amazon.com/step-functions/latest/dg/concepts-statemachines.html)、 AWS Lambda [函数](https://docs.aws.amazon.com/lambda/latest/dg/concepts-basics.html#gettingstarted-concepts-function)、 AWS Identity and Access Management (IAM) [角色](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles.html)和[日志组](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/Working-with-log-groups-and-streams.html)的[AWS CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html)堆栈。然后，您可以运行 Step Functions 工作流程，为您的公交网关创建区域间对等连接。

## 先决条件和限制
<a name="automate-the-setup-of-inter-region-peering-with-aws-transit-gateway-prereqs"></a>

**先决条件**
+ 活跃 AWS 账户的.
+ [具有代码生成功能的 IDE，例如 Kiro。](https://kiro.dev/#what-is-kiro)
+ 亚马逊简单存储服务 (Amazon S3) 存储桶以及向其上传对象的权限。
+ 在请求和接受区域中创建的公交网关。
+ VPCs 在请求和接受区域中创建。 VPCs 使用值为的`addToTransitGateway`密钥标记`true`。
+  VPCs 根据您的要求为您配置@@ [安全组](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-security-groups.html)。
+  VPCs 根据您的要求为您配置的@@ [网络访问控制列表 (ACLs)](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-network-acls.html)。

**限制**
+ 只有部分 AWS 区域 支持跨区域对等。有关支持区域间对等互连的区域的完整列表，请参阅。[AWS Transit Gateway FAQs](https://aws.amazon.com/transit-gateway/faqs/)

## 架构
<a name="automate-the-setup-of-inter-region-peering-with-aws-transit-gateway-architecture"></a>

 此模式中描述的代理人工智能开发方法包括以下步骤：

1. **定义自动化提示** — Kiro 会收到自然语言提示，其中详细说明了对等互连要求。

1. **生成自动化脚本** — Kiro 根据提供的提示生成 CloudFormation 和 Lambda 脚本。

1. **部署堆栈** — Kiro CloudFormation 用于部署所需的资源。

1. **设置对等 — Kiro 运行 Step** Functions 工作流程，该工作流程调用 Lambda 函数来创建对等连接和修改路由表。

下图显示了 Step Functions 的工作流程：

![\[Step Functions 工作流调用 Lambda 函数来修改中转网关对等互连的路由表。\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/images/pattern-img/b678bb87-c7b9-4f7b-b26e-eaac650e5d1b/images/2f235f47-5d68-492c-b954-7dc170939cae.png)


 

工作流包含以下步骤：

1. Step Functions 工作流程为 Transit Gateway 对等互连调用 Lambda 函数。 

1. 工作流程等待一分钟。

1. 工作流程检索对等互连状态并将其发送到条件块。数据块负责循环。 

1. 如未满足成功条件，则对工作流进行编码以进入计时器阶段。 

1. 如果满足成功条件，Lambda 函数将修改路由表。

1. Step Functions 工作流程结束。

## 工具
<a name="automate-the-setup-of-inter-region-peering-with-aws-transit-gateway-tools"></a>
+ [AWS CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html)帮助您设置 AWS 资源，快速一致地配置资源，并在和的整个 AWS 账户 生命周期中对其进行管理 AWS 区域。 
+ [Amazon CloudWatch Lo](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html) gs 可帮助您集中所有系统和应用程序的日志， AWS 服务 这样您就可以监控它们并安全地将其存档。
+ [AWS Identity and Access Management](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html)[(](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html)[IAM](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html)[)](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html) 通过控制谁经过身份验证并有权使用 AWS 资源，从而帮助您安全地管理对资源的访问权限。
+ [Kiro](https://kiro.dev/#what-is-kiro) 是一款代理人工智能开发工具，可帮助您通过规范驱动的开发来构建生产就绪型应用程序。 
+ [AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html) 是一项计算服务，可帮助您运行代码，无需预调配或管理服务器。它只在需要时运行您的代码，并自动进行扩展，因此您只需为使用的计算时间付费。
+ [AWS Step Functions](https://docs.aws.amazon.com/step-functions/latest/dg/welcome.html)是一项无服务器编排服务，可帮助您组合 AWS Lambda 功能和其他功能 AWS 服务 来构建关键业务应用程序。  

## 操作说明
<a name="automate-the-setup-of-inter-region-peering-with-aws-transit-gateway-epics"></a>

### 生成 Lambda 和 Step Functions 代码
<a name="generate-lam-and-sfn-code"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 用具体细节填充提示占位符 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/automate-the-setup-of-inter-region-peering-with-aws-transit-gateway.html)或者，您可以将其添加为引用上述变量的内联提示，而无需附加文件作为上下文。 | 常规 AWS，网络管理员 | 
| 创建用于创建对等连接附件的 Lambda 函数。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/automate-the-setup-of-inter-region-peering-with-aws-transit-gateway.html) | 常规 AWS、网络管理员、Prompt 工程 | 
| 创建用于轮询对等连接状态的 Lambda 函数。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/automate-the-setup-of-inter-region-peering-with-aws-transit-gateway.html) | 常规 AWS、网络管理员、Prompt 工程 | 
| 创建一个 Lambda 函数，向两个区域添加静态路由。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/automate-the-setup-of-inter-region-peering-with-aws-transit-gateway.html) | 常规 AWS，网络管理员 | 
| 创建 CloudFormation 模板。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/automate-the-setup-of-inter-region-peering-with-aws-transit-gateway.html) | AWS DevOps、General AWS、Prompt 工程设计 | 

### 部署 AWS 资源
<a name="deploy-the-aws-resources"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 使用提示部署 CloudFormation 堆栈。 | 输入以下提示：<pre>Using the outputs from Prompts 1-4, package and deploy the full stack. Steps:<br /><br />1. For each of the three Python files from Prompts 1-3, create a zip named after the file (e.g. peer-transit-gateway.zip that contains peer-transit-gateway.py).<br />2. Upload all three zips to S3_BUCKET.<br />3. Deploy the CloudFormation template from Prompt 4 to ACTIVE_REGION with S3BucketName=S3_BUCKET and CAPABILITY_NAMED_IAM.<br />4. Initiate the Step Function from the deployed stack.<br /><br />Zip file names must match the S3Key values in the template exactly.</pre> | AWS DevOps、云管理员、常规 AWS、Prompt 工程 | 
| 验证部署。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/automate-the-setup-of-inter-region-peering-with-aws-transit-gateway.html) | 常规 AWS | 

## 相关资源
<a name="automate-the-setup-of-inter-region-peering-with-aws-transit-gateway-resources"></a>
+ [在 Step Functions 中启动状态机执行](https://docs.aws.amazon.com/step-functions/latest/dg/concepts-state-machine-executions.html)
+ [Transit Gateway 对等连接](https://docs.aws.amazon.com/vpc/latest/tgw/tgw-peering.html)
+ [AWS 区域 使用互 VPCs 连 AWS Transit Gateway](https://www.youtube.com/watch?v=cj1rQqLxXU8)（视频）