

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 使用 自動化區域間對等互連的設定 AWS Transit Gateway
<a name="automate-the-setup-of-inter-region-peering-with-aws-transit-gateway"></a>

*Ram Kandaswamy，Amazon Web Services*

## 摘要
<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 流量不會周遊公有網際網路，這可減少威脅向量，例如常見的入侵和分散式阻斷服務 (DDoS) 攻擊。

如果您需要在兩個或多個 之間通訊 AWS 區域，您可以使用區域間傳輸閘道對等互連，在不同區域中的傳輸閘道之間建立對等互連。不過，使用 Transit Gateway 手動設定區域間對等可能既複雜又耗時。此模式提供使用基礎設施做為程式碼 (IaC) 來設定對等互連的指引。如果您必須重複設定多個區域，並為 AWS 帳戶 多區域組織設定使用此方法。

此模式會設定[AWS CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html)堆疊，其中包含 Amazon CloudWatch Logs 中的 AWS Step Functions [anworkflow](https://docs.aws.amazon.com/step-functions/latest/dg/concepts-statemachines.html)、 AWS Lambda [functions](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)。然後，您可以執行 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 Simple Storage Service (Amazon S3) 儲存貯體及其上傳物件的許可。
+ 在請求和接受區域中建立的傳輸閘道。
+ 在請求和接受區域中建立的 VPCs。使用值為 的`addToTransitGateway`金鑰標記 VPCs`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/)。

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

 此模式中描述的代理式 AI 開發方法涉及以下步驟：

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_tw/prescriptive-guidance/latest/patterns/images/pattern-img/b678bb87-c7b9-4f7b-b26e-eaac650e5d1b/images/2f235f47-5d68-492c-b954-7dc170939cae.png)


 

工作流程包含下列步驟：

1. Step Functions 工作流程會呼叫傳輸閘道對等的 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 Logs](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html) 可協助您集中所有系統、應用程式的日誌， 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) 是一種代理式 AI 開發工具，可協助您透過規格驅動的開發來建置生產就緒的應用程式。 
+ [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>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用特定詳細資訊填入提示預留位置 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/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_tw/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_tw/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_tw/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_tw/prescriptive-guidance/latest/patterns/automate-the-setup-of-inter-region-peering-with-aws-transit-gateway.html) | AWS DevOps、一般 AWS、提示工程 | 

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


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用提示部署 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、提示詞工程 | 
| 驗證部署。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/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)
+ [傳輸閘道對等互連附件](https://docs.aws.amazon.com/vpc/latest/tgw/tgw-peering.html)
+ [AWS 區域 使用 跨 互連 VPCs AWS Transit Gateway](https://www.youtube.com/watch?v=cj1rQqLxXU8)（影片）