Sub topic 4
Transit Gateway as a regional router
This chapter assumes you know CIDR blocks, subnets, route tables, and security groups, and that you have used the AWS CLI. A transit gateway is a regional virtual router that connects VPCs and on-premises networks through one hub. You attach each network to it once instead of wiring every pair together.
The working model
A transit gateway (TGW) lives in one AWS Region. It has three parts you will meet in the next chapters:
- Attachments connect a network to the TGW. Types include VPC, VPN, Direct Connect gateway, and peering.
- Transit gateway route tables decide where traffic from an attachment goes.
- Associations and propagation link attachments to those route tables and fill them with routes.
Traffic enters the TGW from an attachment. The TGW looks up the destination in the route table associated with that attachment, then forwards the packet to the attachment that the matching route names.
Why a hub helps
With peering, n VPCs need n(n-1)/2 connections. Ten VPCs need 45. With a TGW they need 10 attachments. Adding an eleventh VPC adds one attachment, not ten peerings. Routing through the hub is also transitive: VPC A can reach VPC C through the TGW without a direct link.
Creating a transit gateway
The command below creates a TGW. It turns off the default route table association and propagation, so you control routing explicitly.
aws ec2 create-transit-gateway \
--description "hub" \
--options AmazonSideAsn=64512,DefaultRouteTableAssociation=disable,DefaultRouteTablePropagation=disableAmazonSideAsn is the BGP autonomous system number the TGW uses when it talks to VPN or Direct Connect peers. Pick a private ASN that does not clash with your on-premises network. Creation takes a few minutes. Wait until the state is available before you attach anything:
aws ec2 describe-transit-gateways \
--query "TransitGateways[].[TransitGatewayId,State]" \
--output textCommon errors
- Expecting cross-Region reach. A TGW is regional. To connect Regions you peer two TGWs, which a later chapter covers.
- Leaving default association on without a plan. The defaults put every attachment in one shared table, so every VPC can reach every other VPC. That is rarely what you want for production and test.
- Overlapping CIDRs. The TGW cannot route between two attachments that use the same range. Plan address space first.
- Assuming the TGW alone is enough. Even with a TGW, you still need routes in each VPC's route table and permissive security groups. Later chapters cover both.
Exercise
A company has 12 VPCs in one Region and wants any VPC to reach any other. How many peering connections would a full mesh need, and how many TGW attachments would replace them?
Show answer
A full mesh needs 12 × 11 / 2 = 66 peering connections. A transit gateway needs 12 VPC attachments, one per VPC.