View a markdown version of this page

を使用したリージョン間ピアリングの設定を自動化する AWS Transit Gateway - AWS 規範ガイダンス

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

を使用したリージョン間ピアリングの設定を自動化する AWS Transit Gateway

Ram Kandaswamy (Amazon Web Services)

概要

AWS Transit Gateway は、中央ハブを介して仮想プライベートクラウド (VPCs) とオンプレミスネットワークを接続します。Transit Gateway トラフィックはパブリックインターネットを経由しないため、一般的なエクスプロイトや分散型サービス拒否 (DDoS) 攻撃などの脅威ベクトルが軽減されます。

2 つ以上の 間で通信する必要がある場合は AWS リージョン、リージョン間 Transit Gateway ピアリングを使用して、異なるリージョンの Transit Gateway 間でピアリング接続を確立できます。ただし、Transit Gateway とのリージョン間ピアリングを手動で設定すると、複雑で時間がかかる場合があります。このパターンは、Infrastructure as Code (IaC) を使用してピアリングをセットアップするためのガイダンスを提供します。このアプローチは、複数のリージョンを繰り返し設定する必要がある場合や、マルチリージョンの組織設定 AWS アカウント に使用することができます。

このパターンは、Amazon CloudWatch Logs の AWS Step Functions ワークフロー、関数、 AWS Identity and Access Management (IAM) ロールロググループを含む AWS CloudFormationスタックを設定します。 AWS Lambda https://docs.aws.amazon.com/lambda/latest/dg/concepts-basics.html#gettingstarted-concepts-function次に、Step Functions ワークフローを実行して、トランジットゲートウェイのリージョン間ピアリング接続を作成します。

前提条件と制限事項

前提条件

  • アクティブ AWS アカウント。

  • Kiro などのコード生成機能を持つ IDE。

  • Amazon Simple Storage Service (Amazon S3) バケットとそのバケットにオブジェクトをアップロードするためのアクセス許可。

  • リクエスト元のリージョンと受け入れ先のリージョンで作成されたトランジットゲートウェイ。

  • リクエスト元のリージョンと受け入れ先のリージョンで作成された VPCs。VPCsを持つ addToTransitGatewayキーをタグ付けしますtrue

  • 要件に従って VPCs 用に設定されたセキュリティグループ

  • 要件に従って VPCs 用に設定されたネットワークアクセスコントロールリスト (ACLs)

制限事項

  • 一部の のみがリージョン間ピアリング AWS リージョン をサポートしています。リージョン間ピアリングをサポートするリージョンの完全なリストについては、AWS Transit Gateway FAQsを参照してください。

アーキテクチャ

このパターンで説明されているエージェント AI 開発アプローチには、次のステップが含まれます。

  1. 自動化プロンプトを定義する – Kiro は、ピアリング要件の詳細を示す自然言語プロンプトを受け取ります。

  2. 自動化スクリプトの生成 – Kiro は、提供されたプロンプトに基づいて CloudFormation スクリプトと Lambda スクリプトを生成します。

  3. スタックをデプロイする – Kiro は CloudFormation を使用して必要なリソースをデプロイします。

  4. ピアリングの設定 – Kiro は Step Functions ワークフローを実行します。このワークフローは Lambda 関数を呼び出してピアリング接続を作成し、ルートテーブルを変更します。

次の図は、Step Functions ワークフローを示しています。

トランジットゲートウェイピアリング用の Lambda 関数を呼び出すための Step Function ワークフロー。

ワークフローの主なステップは、次のとおりです。

  1. Step Functions ワークフローは、Transit Gateway ピアリングの Lambda 関数を呼び出します。 

  2. ワークフローは 1 分間待機します。

  3. ワークフローはピアリングステータスを取得し、条件ブロックに送信します。ブロックがルーピングを実行します。 

  4. 成功条件が満たされない場合、ワークフローはタイマーステージに移行するようにコーディングされます。 

  5. 成功条件が満たされた場合、Lambda 関数はルートテーブルを変更します。

  6. Step Functions ワークフローは終了します。

ツール

  • AWS CloudFormation は、 AWS リソースをセットアップし、迅速かつ一貫してプロビジョニングし、 AWS アカウント および 全体のライフサイクルを通じてリソースを管理するのに役立ちます AWS リージョン。 

  • Amazon CloudWatch Logs を使用すると、すべてのシステム、アプリケーション、および からのログを一元化 AWS のサービス できるため、ログをモニタリングして安全にアーカイブできます。

  • AWS Identity and Access Management (IAM) は、リソースの使用を認証および認可されたユーザーを制御することで、 AWS リソースへのアクセスを安全に管理できます。

  • Kiro は、スペック駆動型開発を通じて本番環境対応のアプリケーションを構築するのに役立つエージェント AI 開発ツールです。 

  • AWS Lambda は、サーバーのプロビジョニングや管理を行うことなくコードを実行できるコンピューティングサービスです。必要に応じてコードを実行し、自動的にスケーリングするため、課金は実際に使用したコンピューティング時間に対してのみ発生します。

  • AWS Step Functions は、 AWS Lambda 関数やその他の を組み合わせてビジネスクリティカルなアプリケーション AWS のサービス を構築するのに役立つサーバーレスオーケストレーションサービスです。  

エピック

タスク説明必要なスキル

プロンプトプレースホルダーに特定の詳細を入力する

  1. AWS リージョン および バケット名を置き換えて、次のプロンプトを更新します。

    - Active region: ACTIVE_REGION - Passive region: PASSIVE_REGION - S3_BUCKET : my-lambda-packages-bucket - STACK_NAME : transit-gateway-peering - All Lambda functions use two boto3 EC2 clients at module level (one per region), each with signature_version v4 and retries max_attempts=1 mode=standard. - Print all API responses for CloudWatch logging.
  2. これをマークダウンファイルとして保存します。

  3. このマークダウンファイルをコンテキスト用に Kiro プロジェクトに追加します。

注記

または、ファイルをコンテキストにアタッチせずに、上記の変数を参照するインラインプロンプトとして追加することもできます。

AWS 全般、ネットワーク管理者

ピアリングアタッチメントを作成する Lambda 関数を作成します。

  1. Kiro プロジェクトで、次のプロンプトを入力します。

    Write a Python Lambda that creates a transit gateway peering attachment from active region to passive region. Both of these regions will be read as environment variables of the Lambda function. Use two boto3 EC2 clients at the module level, one per Region. The handler should describe available transit gateways in both Regions. Then check if a peering attachment already exists on the active side by filtering describe_transit_gateway_attachments for resource-type "peering" and states: available, initiatingRequest, modifying, pendingAcceptance, pending, rejected, and rejecting. Only if zero results, create the peering attachment with tags for both Transit Gateway IDs, then wait 60 seconds (AWS needs this before the passive side can accept), then call accept_transit_gateway_peering_attachment on the passive client. Print all API responses.
  2. このファイル名を peer-transit-gateway.py として保存します。

AWS 全般、ネットワーク管理者、プロンプトエンジニアリング

ピアリングアタッチメントのステータスをポーリングする Lambda 関数を作成します。

  1. Kiro プロジェクトで、次のプロンプトを入力します。

    Using the shared context above, write a Python Lambda that polls peering attachment status. Describe available transit gateways in both regions, then call describe_transit_gateway_attachments on the active client filtered by the active Transit Gateway ID only (no resource-type filter). Return exactly `{'status': status}` where status is the State field from the first attachment. Do not return statusCode or body — the Step Function Choice state reads `$.Payload.status` and compares to "available".
  2. このファイル名を get-transit-gateway-peering-status.py として保存します。

AWS 全般、ネットワーク管理者、プロンプトエンジニアリング

両方のリージョンに静的ルートを追加する Lambda 関数を作成します。

  1. Kiro プロジェクトで、次のプロンプトを入力します。

    Using the shared context, write a Python Lambda that adds static routes to both regions' TGW route tables. Describe available transit gateways in both Regions, extract each transit gateway's AssociationDefaultRouteTableId. Discover routable VPCs by filtering describe_vpcs with tag `addtotransitgateway=true` in each region, collecting their CIDRs. Get the peering attachment ID from the active side by filtering on the active route table ID. For each passive CIDR, search the active route table using `route-search.exact-match` — only create the route if none found. For each active CIDR, search the passive route table using `route-search.supernet-of-match` (not exact-match — passive side may have supernet routes) — only create if none found. Both sides use the same peering attachment ID.
  2. このファイルを保存し、 という名前を付けますmodify-transit-gateway-routes.py

AWS 全般、ネットワーク管理者

CloudFormation テンプレートを作成します。

  1. CloudFormation テンプレートを作成する次のオーケストレーションプロンプトを入力します。

    Write a CloudFormation JSON template that deploys: three Lambda functions (peer-transit-gateway with 600s timeout, get-transit-gateway-peering-status with 30s timeout, modify-transit-gateway-routes with 600s timeout), Lambda code from an S3 bucket parameter (no default value — user must supply the bucket name at deploy time), a Step Functions state machine, and CloudWatch log groups with 90-day retention. The state machine flow is: 1. Invoke peer-transit-gateway 2. Wait 20 seconds (attachment needs time after the Lambda's internal 20s sleep + acceptance) 3. Invoke get-transit-gateway-peering-status 4. Choice: if `$.Payload.status` equals "available" → go to step 5, otherwise loop back to step 2 5. Invoke modify-transit-gateway-routes → End Use `Fn::Sub` with Lambda ARN references like `${PeerTransitGateways.Arn}` in the DefinitionString. The polling loop has no max retry — it loops until "available" (typically 3-5 minutes total).
  2. ファイルを保存して transit-gateway-peering.json という名前を付けます。

AWS DevOps、AWS 全般、プロンプトエンジニアリング
タスク説明必要なスキル

プロンプトを使用して CloudFormation スタックをデプロイします。

次のプロンプトを入力します。

Using the outputs from Prompts 1-4, package and deploy the full stack. Steps: 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). 2. Upload all three zips to S3_BUCKET. 3. Deploy the CloudFormation template from Prompt 4 to ACTIVE_REGION with S3BucketName=S3_BUCKET and CAPABILITY_NAMED_IAM. 4. Initiate the Step Function from the deployed stack. Zip file names must match the S3Key values in the template exactly.
AWS DevOps、クラウド管理者、AWS 全般、プロンプトエンジニアリング

デプロイを検証します。

  1. Step Functions ワークフローをモニタリングして、正常に完了することを確認します。手順については、Step Functions のドキュメントを参照してください。

  2. Transit Gateway アタッチメントピアリングのステータスが使用可能であることを確認します。手順については、Transit Gateway のドキュメントを参照してください。

AWS 全般

関連リソース