Skip to content

Transit Gateway

๐Ÿš‡ What is AWS Transit Gateway?

AWS Transit Gateway (TGW) is a highly available, fully managed AWS service that acts as a central router to connect:

  • Multiple VPCs

  • Site-to-Site VPNs

  • AWS Direct Connect

  • Third-party appliances (via EC2 or partners)

โœ… Think of it as a hub-and-spoke architecture to reduce complexity, cost, and management overhead.


๐ŸŽฏ Why Use Transit Gateway?

Use Case Benefit
Connect 100s of VPCs securely Centralized routing
Hybrid cloud with VPN and Direct Connect Unified connectivity hub
Multi-region application communication Cross-region peering
Replace VPC peering (complex at scale) Simpler, scalable alternative

๐Ÿงฑ Key Components

Component Description
Transit Gateway (TGW) The core routing hub (like a virtual router)
Attachment Connects a VPC, VPN, or DX to TGW
Route Table Determines how traffic is routed through TGW
Propagation Auto-learns routes from attachments
TGW Peering Used to connect TGWs across regions

๐ŸŽจ Architecture (Hub-and-Spoke)

                 +----------------+
                 | On-prem (VPN)  |
                 +----------------+
                        โ”‚
                        โ–ผ
                  +-------------+              +-------------+
                  |   VPC-A     |โ—€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ–ถ   VPC-B     |
                  +-------------+     โ”‚   โ”‚     +-------------+
                                      โ–ผ   โ–ผ
                                +------------------+
                                |  Transit Gateway |
                                +------------------+
                                      โ–ฒ   โ–ฒ
                  +-------------+     โ”‚   โ”‚     +-------------+
                  |  Direct CX  |โ”€โ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ–ถ   VPC-C     |
                  +-------------+                     |
                                                   +-------------+
                                                   |  VPC-D (DR) |
                                                   +-------------+

๐Ÿ› ๏ธ How to Create and Use a Transit Gateway

โœ… Step 1: Create a Transit Gateway

  • Go to VPC > Transit Gateways > Create

  • Choose:

    • Auto-accept shared attachments (optional)

    • Default route table association/propagation

    • DNS support

    • Multicast support (if needed)

    • ASN (for BGP if used)

aws ec2 create-transit-gateway \
  --description "Central TGW" \
  --options AmazonSideAsn=64512

โœ… Step 2: Attach a VPC to TGW

  • Go to Transit Gateway Attachments > Create

  • Select:

    • TGW ID

    • VPC ID

    • Subnets (in each AZ for HA)

aws ec2 create-transit-gateway-vpc-attachment \
  --transit-gateway-id tgw-abc123 \
  --vpc-id vpc-xyz456 \
  --subnet-ids subnet-aaa111 subnet-bbb222

โš ๏ธ You must select at least one subnet per AZ to allow traffic through.


โœ… Step 3: Update Route Tables

VPC Route Table:

  • Add a route for destination CIDR to TGW

Transit Gateway Route Table:

  • Associate and propagate attachments

  • Control what attachment can reach what destination


โœ… Step 4: Add Other Attachments

You can attach:

  • VPN Connections

  • Direct Connect Gateways

  • Other VPCs

  • Peered TGWs (cross-region)


๐Ÿง  Route Table Strategy

You can create multiple TGW route tables for isolation.

Use Case Strategy
Shared services VPCs propagate to TGW shared route table
Dev/Prod isolation Use separate TGW route tables
East-West routing Use one table or custom ones

๐Ÿ“ฆ Transit Gateway Peering

  • Enables TGW-to-TGW connection across AWS Regions

  • Fully private and uses AWS backbone

  • Supports IPv4 & IPv6, inter-region VPC communication

aws ec2 create-transit-gateway-peering-attachment \
  --transit-gateway-id tgw-123 \
  --peer-transit-gateway-id tgw-456 \
  --peer-region us-west-2

๐Ÿงช Monitoring and Logging

Feature Use
CloudWatch Metrics Packet count, bytes in/out, attachment status
VPC Flow Logs Inspect traffic per interface
Transit Gateway Logging Optional logging to CloudWatch or S3 (flow log-like)

๐Ÿ” Security Tips

Recommendation Reason
Use IAM policies + Resource Access Manager (RAM) Control who shares/attaches to TGW
Use separate route tables Enforce segmentation/isolation
Tag attachments & route tables Easier auditing
Log and monitor traffic Troubleshooting and compliance

Feature Transit Gateway VPC Peering PrivateLink
Pattern Hub-and-spoke Point-to-point Service exposure
Transitive routing โœ… Yes โŒ No โŒ No
# of connections 1000+ VPCs 125 per VPC 50+ endpoints
Multi-account support โœ… Yes (via RAM) โœ… Yes โœ… Yes
Use case Network hub Simple 1:1 VPC link SaaS or internal service exposure

โœ… Best Practices

Tip Why it Matters
Enable auto-propagation carefully Avoid unintended route sharing
Use tags for attachments Easier cost tracking and filtering
Create route tables per environment Better isolation for Dev, Prod, Shared
Use with AWS Resource Access Manager For cross-account VPC attachments
Monitor regularly Avoid route conflicts and ensure HA

โš–๏ธ Cost Overview

Component Pricing
Transit Gateway Per GB of data processed
Attachments No charge to create, only for usage
Peering Per GB (cross-region is more expensive)

โš ๏ธ Ingress and egress traffic through TGW is charged.


๐Ÿ”š TL;DR Summary

Feature Value
What is it? Central router for VPCs, VPNs, DX
Replaces? Complex VPC peering meshes
Supports? Transitive routing, multi-region peering
Max VPCs? 5000+ per TGW (practically scalable)
Uses route tables? โœ… Yes โ€” per attachment routing policies
Can isolate networks? โœ… Yes โ€” by route table separation