Skip to main content

VPC Advanced - Transit Gateway, Direct Connect, and Site-to-Site VPN

Connect multiple VPCs and on-premises networks using Transit Gateway, Direct Connect, Site-to-Site VPN, and Traffic Mirroring for production hybrid architectures.

What you will learn

  • Site-to-Site VPN — Virtual Private Gateway, Customer Gateway, and route propagation
  • VPN CloudHub — connecting multiple branch offices using one Virtual Private Gateway
  • Direct Connect — Private VIF vs Public VIF, DX Gateway for multi-region access
  • Why Direct Connect alone is not encrypted and what to do about it
  • Direct Connect resiliency levels — the four tiers from basic to maximum
  • AWS Transit Gateway — hub-and-spoke replacing mesh VPC peering
  • ECMP and bandwidth multiplication through multiple VPN tunnels to Transit Gateway
  • VPC Traffic Mirroring — capture live network traffic for security analysis
  • IPv6 on AWS and the Egress-Only Internet Gateway for outbound-only IPv6
  • AWS Network Firewall — stateful Layer 7 inspection inside your VPC

Why this matters

A large Indian enterprise — bank, insurance company, or government organisation — runs applications on-premises in their data centre and needs to extend into AWS. Simply exposing those applications to the public internet is not acceptable for compliance reasons. Site-to-Site VPN creates an encrypted private tunnel. But VPN over the public internet still has variable latency and packet loss. Direct Connect provides a dedicated private fibre connection with consistent latency — the right choice for latency-sensitive trading systems or high-volume data pipelines. As the company grows and creates 20 VPCs across accounts, Transit Gateway replaces a tangle of hundreds of individual peering connections with one central hub. Understanding these connectivity patterns is what separates an engineer who can design hybrid architectures from one who can only describe them.

Site-to-Site VPN

Site-to-Site VPN creates an encrypted tunnel over the public internet between your on-premises network and your AWS VPC. All traffic flows through this encrypted tunnel — as if the two networks were directly connected.

Two endpoints:

◈ DIAGRAM
Virtual Private Gateway (VGW):
AWS side of the tunnel
Attached to your VPC
One VPC → one VGW
Customer Gateway (CGW):
Your side of the tunnel
A software resource in AWS representing your on-premises router or firewall
You create it in AWS with the public IP of your on-premises device

Setup flow:

◈ DIAGRAM
On-premises router (public IP: 203.0.113.5)
↓ encrypted IPSec tunnel over public internet
Virtual Private Gateway (attached to your VPC)
↓
Your private VPC resources

Route Propagation:

Without route propagation you manually add routes to your VPC route table pointing on-premises CIDRs to the VGW. With Route Propagation enabled, the VGW automatically adds routes learned from the on-premises router via BGP.

Bash
## Create a Customer Gateway representing your on-premises router
aws ec2 create-customer-gateway \
--type ipsec.1 \
--public-ip 203.0.113.5 \
--bgp-asn 65000 \
--region ap-south-1
## Create a Virtual Private Gateway and attach to VPC
aws ec2 create-vpn-gateway \
--type ipsec.1 \
--region ap-south-1
aws ec2 attach-vpn-gateway \
--vpn-gateway-id vgw-0abc123456789def \
--vpc-id vpc-0abc123456789def \
--region ap-south-1
## Create the VPN connection
aws ec2 create-vpn-connection \
--type ipsec.1 \
--customer-gateway-id cgw-0abc123456789def \
--vpn-gateway-id vgw-0abc123456789def \
--options StaticRoutesOnly=false \
--region ap-south-1
## Enable route propagation on private route table
aws ec2 enable-vgw-route-propagation \
--route-table-id rtb-private-abc123 \
--gateway-id vgw-0abc123456789def \
--region ap-south-1
Remember

Each VPN connection consists of TWO IPSec tunnels for high availability. AWS provides two tunnel endpoints — configure both on your on-premises router so if one fails, traffic automatically flows through the other.

AWS VPN CloudHub

You have five branch offices — Delhi, Mumbai, Hyderabad, Pune, and Bangalore. Each needs to connect to AWS. Each also needs to connect to the other branches. Normally that would require connecting each branch to AWS and setting up meshed VPN tunnels between offices.

VPN CloudHub solves this with a hub-and-spoke model using one Virtual Private Gateway.

◈ DIAGRAM
Delhi branch ──────┐
Mumbai branch ──────┤
Hyderabad branch ──────┼──> Virtual Private Gateway (hub)
Pune branch ──────┤
Bangalore branch ──────┘
Delhi to Hyderabad traffic:
Delhi → VGW → Hyderabad (traffic routed through the hub automatically)

All branches connect to the same VGW. AWS routes traffic between them. No direct branch-to-branch tunnels needed. Low cost, works over the public internet, encrypted via IPSec.

Remember

VPN CloudHub traffic between branches travels through the VGW in AWS. It does NOT have access to resources inside the VPC unless explicitly configured. The VGW is the hub for branch connectivity — VPC access is separate.

AWS Direct Connect (DX)

Site-to-Site VPN uses the public internet — variable latency, packet loss possible, shared bandwidth. Direct Connect bypasses the public internet entirely with a dedicated physical fibre connection from your data centre to an AWS Direct Connect location.

◈ DIAGRAM
Data centre → (private fibre) → DX Location → (AWS network) → Your VPC
DX gives you:
Consistent network performance — dedicated bandwidth, no sharing
Reduced bandwidth costs for high-volume data transfers
Private connectivity — traffic never touches the public internet

DX bandwidth options: 1 Gbps, 10 Gbps, 100 Gbps. For smaller needs, partner connections from 50 Mbps.

Security

Direct Connect is NOT encrypted by default. It is a private connection but the traffic is not encrypted. For data that requires encryption in transit (financial data, PII), run IPSec VPN over Direct Connect or use MACsec where supported.

Two types of Virtual Interfaces (VIFs):

TEXT
Private VIF:
Connects to one VPC via a VGW
Access private resources inside the VPC (EC2, RDS, ElastiCache)
Traffic stays on private IP addresses
Public VIF:
Connects to AWS public services (S3, DynamoDB, Glacier)
Traffic uses public IP space but still travels on DX — not public internet
Use when: downloading from S3 over DX without internet charges

Direct Connect Gateway — one DX connection, multiple VPCs and regions:

Without DX Gateway, a single DX connection reaches one VPC in one region via a Private VIF. To reach VPCs in different regions you need separate DX connections.

DX Gateway solves this:

◈ DIAGRAM
On-premises data centre
↓ Single Direct Connect connection
DX Gateway (global, not region-specific)
├── VPC in ap-south-1
├── VPC in ap-southeast-1
└── VPC in us-east-1

One physical DX connection, access to VPCs worldwide through the DX Gateway.

Direct Connect Resiliency Levels:

Level Setup Protects against
Non-redundant One DX connection, one location Nothing — single point of failure
High Resiliency Two DX connections, two locations Single connection or location failure
Maximum Resiliency Four DX connections, two locations Two simultaneous location failures
Backup VPN DX primary + Site-to-Site VPN fallback DX failure (VPN is the backup)
Remember

For maximum resiliency you need DX connections at two geographically separate DX locations with two connections at each location — four connections total. This protects against any single location going offline.

AWS Transit Gateway

VPC Peering works for a small number of VPCs. You have 10 VPCs and every pair needs to communicate: that is 10×9/2 = 45 peering connections. You have 20 VPCs: 190 connections. Each peer must be managed individually with its own route tables.

Transit Gateway is a regional network transit hub. Every VPC and on-premises connection attaches to the TGW. Traffic between any two attachments routes through the TGW automatically.

TEXT
Without Transit Gateway (10 VPCs, meshed peering):
45 individual VPC peering connections
45 pairs of route table entries
Every new VPC requires connections to all 9 others
With Transit Gateway (10 VPCs, hub-and-spoke):
10 attachments to TGW — one per VPC
10 route table entries
New VPC: one new attachment, done

How Transit Gateway routes:

◈ DIAGRAM
VPC A (10.0.0.0/16) ──────┐
VPC B (10.1.0.0/16) ──────┤
VPC C (10.2.0.0/16) ──────┼──> Transit Gateway ──> (routes to all)
On-prem (192.168.0.0) ──────┤
VPN Connection ──────┘

Key TGW facts:

TEXT
Regional resource — VPCs in the same region attach directly
Cross-region peering — TGW in ap-south-1 can peer with TGW in us-east-1
Scales to thousands of VPCs and on-premises connections
Supports IP Multicast (the only AWS service that does)
Route tables on TGW control which attachments can reach which

ECMP — Bandwidth Multiplication with Multiple VPNs:

ECMP (Equal Cost Multi-Path) routing allows traffic to flow over multiple paths simultaneously when they have equal routing cost.

◈ DIAGRAM
Without ECMP:
VPN tunnel 1 → 1.25 Gbps max (VPN tunnel limit)
All traffic uses tunnel 1 → tunnel 2 is only a failover
With TGW + ECMP + multiple VPN connections:
VPN connection 1 (2 tunnels: 1.25 Gbps each) ──┐
VPN connection 2 (2 tunnels: 1.25 Gbps each) ──┤──> TGW (ECMP balances)
VPN connection 3 (2 tunnels: 1.25 Gbps each) ──┘
Total effective bandwidth: up to 3 × 2.5 Gbps = 7.5 Gbps
Add more VPN connections → multiply bandwidth further
Remember

VPC Peering only works through TGW — it does not support transitive routing. If VPC A peers with TGW and VPC B peers with TGW, A and B can talk through TGW. But if A peers directly with B and B peers directly with C, A cannot reach C through B — transitive peering is not supported and never was.

VPC Traffic Mirroring

Traffic Mirroring copies live network traffic from EC2 instances (ENIs) and sends it to a monitoring appliance for analysis — without affecting the original traffic.

◈ DIAGRAM
Source: An ENI on a production EC2 instance
Filter: Which traffic to copy (by port, CIDR, protocol)
Target: A Network Load Balancer or an ENI receiving the mirrored copy
Appliance: Your security tool (IDS, Wireshark, packet analyser) receives the copy
Production traffic: Request → EC2 → Response (unaffected, normal flow)
↓ (copy sent simultaneously)
Monitoring Appliance (receives mirror, analyses patterns)

Use cases:

TEXT
Network security analysis and threat detection
Troubleshoot network connectivity issues with full packet capture
Detect data exfiltration attempts by analysing outbound traffic patterns
Compliance — full packet capture for financial regulations

IPv6 and Egress-Only Internet Gateway

IPv4 addresses are running out globally. IPv6 provides a vastly larger address space.

In AWS, IPv6 addresses are always public and internet-routable. There are no private IPv6 addresses in the way there are private IPv4 ranges (10.x.x.x, 192.168.x.x).

The problem with public IPv6 in private subnets:

Private subnets should be unreachable from the internet. With IPv4, NAT Gateway prevents inbound connections. With IPv6, there is no NAT — all addresses are public.

Egress-Only Internet Gateway:

Works like an Internet Gateway but for IPv6 — allows outbound IPv6 traffic from your VPC while blocking all inbound IPv6 connections from the internet.

◈ DIAGRAM
Private IPv6 instance:
Outbound: request → EIGW → internet → response back through EIGW → instance ✓
Inbound: internet → EIGW → BLOCKED ✗
EIGW for IPv6 = NAT Gateway for IPv4 (conceptually)

Route table entry for EIGW:

◈ DIAGRAM
Private route table with IPv6:
Destination Target
10.0.0.0/16 local
::/0 eigw-abc123 ← all IPv6 traffic to EIGW (outbound only)

AWS Network Firewall

A Security Group is a simple stateless (NACLs) or stateful (SGs) packet filter. WAF is Layer 7 for HTTP only. For full stateful Layer 7 inspection of ALL traffic inside your VPC — any protocol, not just HTTP — use AWS Network Firewall.

TEXT
Network Firewall capabilities:
Stateful packet inspection (tracks connection state)
URL/domain filtering — block specific hostnames
Protocol-based rules — allow only HTTPS, block FTP
Intrusion Detection and Prevention (IDS/IPS) using Suricata rules
AWS-managed rule groups updated automatically with threat intelligence

Network Firewall deployment:

◈ DIAGRAM
Internet
↓
Network Firewall (in its own subnet per AZ)
↓ (inspects and passes or drops)
Application Load Balancer (in public subnets)
↓
EC2 instances (in private subnets)

Route tables direct traffic through the firewall subnet before it reaches the application. Traffic that does not pass inspection is dropped.

Network Firewall vs WAF vs Security Groups:

Security Groups NACLs WAF Network Firewall
Layer 4 (instance level) 3-4 (subnet level) 7 HTTP only 3-7 all protocols
Stateful Yes No Yes Yes
URL filtering No No Yes Yes
IDS/IPS No No No Yes
Protocols Any Any HTTP/HTTPS Any
Remember

WAF = Layer 7 HTTP/HTTPS inspection for public-facing ALB, CloudFront, API Gateway. Network Firewall = stateful deep packet inspection for all traffic (any protocol) flowing between subnets inside your VPC. They solve different problems and can both be used together.

Hands-on Lab — Transit Gateway Connecting Two VPCs

Step 1 — Create two VPCs

◈ DIAGRAM
VPC → Your VPCs → Create VPC
Name: vpc-a IPv4 CIDR: 10.1.0.0/16 Create
Create again:
Name: vpc-b IPv4 CIDR: 10.2.0.0/16 Create
Create one private subnet in each:
vpc-a: subnet 10.1.1.0/24 in ap-south-1a
vpc-b: subnet 10.2.1.0/24 in ap-south-1a

Step 2 — Create a Transit Gateway

◈ DIAGRAM
VPC → Transit Gateways → Create transit gateway
Name: devops-tgw
Default route table association: Enable
Default route table propagation: Enable
Create transit gateway — wait until Available (2-3 minutes)

Step 3 — Attach both VPCs to the Transit Gateway

◈ DIAGRAM
VPC → Transit Gateway Attachments → Create attachment
Transit gateway: devops-tgw
Attachment type: VPC
VPC: vpc-a Subnet: 10.1.1.0/24
Create attachment
Create another:
Transit gateway: devops-tgw
VPC: vpc-b Subnet: 10.2.1.0/24
Create attachment
Wait until both show state: Available

Step 4 — Update Route Tables

◈ DIAGRAM
vpc-a private route table → Routes → Edit → Add route:
Destination: 10.2.0.0/16 Target: devops-tgw
vpc-b private route table → Routes → Edit → Add route:
Destination: 10.1.0.0/16 Target: devops-tgw
Now instances in vpc-a can reach instances in vpc-b using private IPs.
Traffic flows: vpc-a instance → TGW → vpc-b instance
No internet involved. Private routing throughout.

Step 5 — Verify connectivity

TEXT
Launch one EC2 in vpc-a subnet and one in vpc-b subnet.
From vpc-a EC2, ping the private IP of vpc-b EC2.
Without TGW: unreachable.
With TGW: ping succeeds — two separate VPCs, private routing.

Step 6 — Cleanup

TEXT
Delete TGW Attachments (both) — wait until deleted
Delete Transit Gateway
Terminate EC2 instances
Delete subnets, route tables, then VPCs

Production Best Practices and Common Pitfalls

  • Use Transit Gateway instead of VPC peering when you have more than 5 VPCs — peering does not scale, TGW does
  • Run Site-to-Site VPN as backup for Direct Connect — DX alone without VPN fallback means a physical cable cut takes your hybrid connectivity offline
  • Encrypt Direct Connect traffic with IPSec VPN over DX or MACsec — DX is private but not encrypted
  • Configure both VPN tunnels on your on-premises router — AWS provides two tunnels per VPN connection, use both for HA
  • Use ECMP with multiple VPN connections to Transit Gateway when you need more than 1.25 Gbps of VPN throughput
  • Enable route propagation on private route tables — avoids manual route management as on-premises routes change
  • Use Network Firewall for east-west traffic inspection between VPCs connected via TGW — Security Groups alone cannot inspect cross-VPC traffic at Layer 7

Quick Reference and Troubleshooting Commands

Task Command
List Transit Gateways aws ec2 describe-transit-gateways --region ap-south-1
List TGW attachments aws ec2 describe-transit-gateway-vpc-attachments --region ap-south-1
List TGW route tables aws ec2 describe-transit-gateway-route-tables --region ap-south-1
List VPN connections aws ec2 describe-vpn-connections --region ap-south-1
Check VPN tunnel status aws ec2 describe-vpn-connections --query 'VpnConnections[*].VgwTelemetry'
List Direct Connect connections aws directconnect describe-connections --region ap-south-1
List DX Virtual Interfaces aws directconnect describe-virtual-interfaces --region ap-south-1
List Traffic Mirror sessions aws ec2 describe-traffic-mirror-sessions --region ap-south-1

Common problems and fixes:

Problem Likely cause Fix
VPN tunnel UP but traffic not routing Route not added in VPC route table Add route for on-premises CIDR pointing to VGW, enable route propagation
TGW attachment in pending state Subnet not in the right AZ or insufficient permissions Check subnet AZ matches TGW AZ support, verify IAM permissions
Cannot reach VPC B from VPC A via TGW Missing route in one or both VPC route tables Add routes in both VPCs pointing opposite CIDR to TGW
DX not providing expected latency improvement Traffic still using internet path Verify BGP routes prefer DX path, check on-premises router BGP config
IPv6 instances reachable from internet Using IGW not EIGW for IPv6 Replace 0::/0 → IGW route with 0::/0 → EIGW in private route table
Common Mistake

Expecting transitive routing through VPC peering. If VPC A peers with VPC B and VPC B peers with VPC C, traffic from A cannot reach C through B. VPC peering is not transitive. For transitive routing between multiple VPCs, use Transit Gateway — it was built specifically for this.

Tip

When you need both Direct Connect for normal operations and a cost-effective backup, configure Site-to-Site VPN as a failover. On your on-premises BGP router, assign a higher BGP metric (lower preference) to the VPN route and a lower metric (higher preference) to the DX route. Traffic uses DX normally. If DX fails, BGP automatically prefers the VPN route and traffic fails over — no manual intervention.

Common Mistakes to Avoid

Common Mistake

Trying to peer VPCs with overlapping CIDR ranges. VPC Peering requires non-overlapping CIDRs — AWS cannot route between identical address spaces. Plan your IP ranges before creating any VPC. Changing a VPC CIDR after creation is not possible.

Common Mistake

Expecting transitive routing through VPC Peering. If VPC A is peered with VPC B, and VPC B is peered with VPC C, A cannot reach C through B. Create a direct peering between A and C, or use Transit Gateway which handles hub-and-spoke routing natively.

Tip

For connecting more than 3 VPCs, Transit Gateway is almost always the right choice over mesh VPC Peering. With 5 VPCs and full mesh peering you need 10 peering connections. With Transit Gateway you need 5 attachments and one TGW.

Resources

AWS Direct Connect vs Site-to-Site VPN Failover

AWS Direct Connect vs Site-to-Site VPN Failover

Direct Connect vs VPN isn't really either/or for production — it's a primary-plus-failover pattern. Here's how to design it, and when either/or is right.

5 min read•Aug 2026
Lambda vs Fargate vs EC2 Spot: The Cost Crossover

Lambda vs Fargate vs EC2 Spot: The Cost Crossover

Lambda vs Fargate vs EC2 Spot, at the crossover where Lambda stops being cheaper — 2026 pricing, invocation thresholds, and interruption math.

5 min read•Aug 2026
Secrets Manager vs Parameter Store vs Vault

Secrets Manager vs Parameter Store vs Vault

AWS Secrets Manager, Parameter Store, and HashiCorp Vault compared for 2026 - cost math, rotation, multi-cloud fit, and the Vault-to-OpenBao fork.

5 min read•Aug 2026
AWS VPC Security: Hardening Every Layer

AWS VPC Security: Hardening Every Layer

Most cloud security incidents start with a misconfigured VPC. Here's how to harden every layer — subnets, Security Groups, NACLs, and IAM — for production.

5 min read•Jul 2026
Event-Driven Architecture on AWS Explained

Event-Driven Architecture on AWS Explained

Event-driven architecture on AWS decouples services and absorbs traffic spikes using SQS, SNS, EventBridge, and Lambda — workflows that scale themselves.

5 min read•Jul 2026
S3 vs RDS vs DynamoDB: Choosing AWS Storage

S3 vs RDS vs DynamoDB: Choosing AWS Storage

Choosing S3, RDS, or DynamoDB wrong costs you in performance, cost, and scalability. Here is a practical decision guide based on your actual access patterns.

5 min read•Jul 2026
AWS Cost Optimisation: Cut Cloud Bills 40-60%

AWS Cost Optimisation: Cut Cloud Bills 40-60%

AWS bills surprise teams every month. Here are the 8 concrete actions that cut cloud spend by 40-60% without touching your application architecture.

5 min read•Jul 2026
EC2 vs Lambda vs Fargate: Choosing AWS Compute

EC2 vs Lambda vs Fargate: Choosing AWS Compute

EC2, Lambda, or Fargate — choosing the wrong AWS compute option costs you money and performance. Here is exactly when to use each one in production.

5 min read•Jul 2026

Explore More in AWS Networking and Security

All 6 Topics

Frequently Asked Questions

Is VPC Advanced - Transit Gateway, Direct Connect, and Site-to-Site VPN free to learn on DevOps Network?

Yes - this topic, like everything on DevOps Network, is 100% free with no paywall or sign-up gate.

What does the VPC Advanced - Transit Gateway, Direct Connect, and Site-to-Site VPN topic cover?

Connect multiple VPCs and on-premises networks using Transit Gateway, Direct Connect, Site-to-Site VPN, and Traffic Mirroring for production hybrid architectures.