Automate the setup of inter-Region peering with AWS Transit Gateway
Ram Kandaswamy, Amazon Web Services
Summary
AWS Transit Gateway connects virtual private clouds (VPCs) and on-premises networks through a central hub. Transit Gateway traffic doesn't traverse the public internet, which helps reduce exposure to threats such as common exploits and distributed denial of service (DDoS) attacks.
If you need to communicate between two or more AWS Regions, you can use inter-Region Transit Gateway peering to establish peering connections between transit gateways in different Regions. However, manually configuring inter-Region peering with Transit Gateway can be complex and time-consuming. This pattern provides guidance for using infrastructure as code (IaC) to set up peering. You can use this approach if you need to repeatedly configure several Regions and AWS accounts for a multi-Region organization setup.
This pattern sets up an AWS CloudFormationstack that includes an AWS Step Functions workflow, AWS Lambda functions, AWS Identity and Access Management (IAM) roles, and log groups in Amazon CloudWatch Logs. You then run the Step Functions workflow to create the inter-Region peering connection for your transit gateways.
Prerequisites and limitations
Prerequisites
An active AWS account.
An integrated development environment (IDE) that has code-generation capability, such as Kiro
. An Amazon Simple Storage Service (Amazon S3) bucket and permissions to upload objects to it.
AWS Transit Gateway transit gateways created in the requesting and accepting Regions.
Amazon VPC virtual private clouds (VPCs) created in the requesting and accepting Regions. Tag the VPCs with an
addToTransitGatewaykey with a value oftrue.Security groups configured for your VPCs according to your requirements.
Network access control lists (ACLs) configured for your VPCs according to your requirements.
Limitations
Inter-Region peering is available in selected AWS Regions. For a full list of Regions that support inter-Region peering, see the AWS Transit Gateway FAQs
.
Architecture
The agentic AI development approach described in this pattern involves the following steps:
Define the automation prompt – Kiro receives a natural language prompt that details the peering requirements.
Generate automation script – Kiro generates the CloudFormation and Lambda scripts based on the provided prompt.
Deploy the stack – Kiro uses CloudFormation to deploy the required resources.
Set up peering – Kiro runs the Step Functions workflow, which calls Lambda functions to create peering connections and modify route tables.
The following diagram shows the Step Functions workflow:

The workflow contains the following steps:
The Step Functions workflow calls the Lambda function for the Transit Gateway peering.
The workflow waits for one minute.
The workflow retrieves the peering status and sends it to the condition block, which controls the loop.
If the success condition is not met, the workflow returns to the timer stage.
If the success condition is met, a Lambda function modifies the route tables.
The Step Functions workflow ends.
Tools
AWS CloudFormation helps you set up AWS resources, provision them quickly and consistently, and manage them throughout their lifecycle across AWS accounts and AWS Regions.
Amazon CloudWatch Logs helps you centralize the logs from all your systems, applications, and AWS services so you can monitor them and archive them securely.
AWS Identity and Access Management (IAM) helps you securely manage access to your AWS resources by controlling who is authenticated and authorized to use them.
Kiro
is an agentic AI development tool that helps you build production-ready applications through spec-driven development. AWS Lambda is a compute service that helps you run code without needing to provision or manage servers. It runs your code only when needed and scales automatically, so you pay only for the compute time that you use.
AWS Step Functions is a serverless orchestration service that helps you combine AWS Lambda functions and other AWS services to build business-critical applications.
Best practices
Before you generate
Use a non-production AWS account. Run everything in a sandbox or dev account with no access to production data or systems.
Use least-privilege credentials. Don't run Kiro with admin credentials. Grant only the permissions the task needs.
Start from a clean Git branch. Commit your work first so you can review every change Kiro makes with
git diffand roll back easily.Set project rules with steering files. Add your standards to
.kiro/steering/(for example: "never hardcode secrets", "all AWS Identity and Access Management (IAM) policies must be least-privilege", "use parameterized queries"). Kiro applies them to every request, not just this prompt.
While generating
Keep the security requirements in the prompt. The template asks for least-privilege IAM, no hardcoded secrets, input validation, and tests. Don't remove them when you customize it.
Fill in placeholders precisely. Vague inputs lead to guesses. Specify the region, runtime versions, and resource names you actually want.
Use supervised mode for infrastructure changes. Approve each change instead of letting the agent run unattended, especially for anything that creates or modifies cloud resources.
Work in small steps. Generate one component at a time and verify it before moving on, instead of generating the whole solution at once.
Use specs for larger features. Kiro's spec workflow creates requirements, a design, and tasks before writing code, which gives you checkpoints to review the plan before any code is written.
After generating: verify before you trust
Read the code. Make sure you understand what each file does. If you can't explain it, don't deploy it.
Run the tests, and check they test real behavior. Tests that only check mocks the AI also wrote can pass while the real code is broken.
Scan for security issues. For example:
Secrets:
detect-secrets scanorgit secrets --scanPython:
bandit -r .Dependencies:
pip-audit,npm auditInfrastructure:
cfn-lint,cfn-guard,checkov, ortfsec
Vet every dependency. Confirm each package exists, is actively maintained, and isn't a typosquat of a popular name. Pin versions.
Review IAM and network exposure line by line. Look for
"Action": "*","Resource": "*",0.0.0.0/0ingress, public Amazon S3 buckets, and unauthenticated endpoints.Preview infrastructure changes before applying them. Run
terraform plan,cdk diff, or an AWS CloudFormation change set and read what will be created, changed, or deleted.Confirm APIs and versions against official documentation. AI can suggest deprecated parameters or APIs that don't exist.
Before deploying
Get a human code review. Treat AI-generated code like code from a new teammate: it needs a reviewer who didn't write the prompt.
Tag resources and set a budget alert. Tag everything the code creates, and set an AWS Budgets alert so unexpected costs surface early.
Plan cleanup. Know how to remove every resource the code created (for example,
terraform destroyorcdk destroy), and run it when you're done experimenting.
Iterate safely
Treat changes to the generated code as new code. Re-run tests and scans after every follow-up prompt, not just the first one.
Start a fresh session for unrelated tasks. Long conversations can carry over outdated context; a fresh session gives more consistent results.
Epics
| Task | Description | Skills required |
|---|---|---|
Filling prompt placeholders with specific details |
Note Alternatively, you can add this as an inline prompt that references the above variables without attaching the file for context. | General AWS, Network administrator |
Create a Lambda function that creates the peering attachments. |
| General AWS, Network administrator, Prompt engineering |
Create a Lambda function that polls the peering attachment status. |
| General AWS, Network administrator, Prompt engineering |
Create a Lambda function that adds static routes to both Regions. |
| General AWS, Network administrator |
Create the CloudFormation template. |
| AWS DevOps, General AWS, Prompt engineering |
| Task | Description | Skills required |
|---|---|---|
Deploy the CloudFormation stack by using prompts. | Enter the following prompt:
| AWS DevOps, Cloud administrator, General AWS, Prompt engineering |
Validate deployment. |
| General AWS |