Sub topic 4
Transit Gateway as a regional router
This chapter assumes you know CIDR blocks, subnets, route tables, security groups, and network ACLs, and that you can run AWS CLI commands. You also know why peering gets hard to manage past a handful of VPCs, which the previous chapter covered. Here you will build the working model of a transit gateway: what it is, what it routes, what it does not do, and which errors show up first.
What a transit gateway is
A transit gateway (TGW) is a regional virtual router that you create once and connect many networks to. Each connected network is called an attachment. Traffic from one attachment can reach any other attachment, as long as the routing tables inside the transit gateway allow it.
Three properties shape how you use it:
- Regional. A transit gateway lives in one AWS Region. It can attach only VPCs in that Region. Reaching other Regions takes a separate step, covered in a later chapter.
- Layer 3 only. It forwards IP packets by destination address. It does not know about applications, DNS names, or load balancers.
- Transitive. If VPC A and VPC B are both attached, and routing allows it, A can reach B through the hub. Peering cannot do this, because a peering connection only carries traffic between its two endpoints.
The practical effect is that the number of connections grows linearly. Ten VPCs need ten attachments. A full mesh of peering connections between ten VPCs needs 45.
| VPCs | Peering connections for a full mesh | Transit gateway attachments |
|---|---|---|
| 3 | 3 | 3 |
| 10 | 45 | 10 |
| 50 | 1,225 | 50 |
The full-mesh count is n × (n − 1) / 2.
The model: attachments, route tables, and two separate routing layers
A transit gateway does not make routing decisions in one place. Two sets of route tables are involved, and most early mistakes come from confusing them.
- The VPC route table (subnet level) decides whether a packet leaves the subnet toward the transit gateway.
- The transit gateway route table decides which attachment the packet goes to next.
A packet from VPC A to VPC B crosses both layers on the way out and again on the way back. The return path matters as much as the outbound path.
Each attachment is associated with exactly one transit gateway route table. That association decides where the attachment's outbound traffic is looked up. Separately, an attachment can propagate its CIDR into one or more route tables, which is how other attachments learn how to reach it. The next two chapters cover attachments and route tables in detail. For now, remember that association controls where traffic from an attachment is routed, and propagation controls who can send traffic to it.
Creating a transit gateway
The command below creates a transit gateway with default association and propagation turned off. By default, AWS creates one default route table and automatically associates and propagates every new attachment to it, which gives you a flat network where everything can reach everything. Turning the defaults off makes you state your routing explicitly, which is the safer choice once environments need to be isolated.
aws ec2 create-transit-gateway \
--description "hub" \
--options AmazonSideAsn=64512,DefaultRouteTableAssociation=disable,DefaultRouteTablePropagation=disableThe AmazonSideAsn value is the private autonomous system number the transit gateway uses when it exchanges routes over BGP with VPN or Direct Connect attachments. Pick one that does not collide with your on-premises ASN. The default is 64512. You cannot change it after creation without recreating the gateway.
The gateway starts in the pending state and becomes available after a short wait. You can check it with:
aws ec2 describe-transit-gateways \
--transit-gateway-ids tgw-0123456789abcdef0 \
--query "TransitGateways[0].State"You cannot create attachments until the state is available.
What you can attach
A transit gateway is a hub for several kinds of attachment:
| Attachment type | What it connects | Routing source |
|---|---|---|
| VPC | A VPC in the same Region | Propagated CIDRs or static routes |
| VPN | A site-to-site VPN to an on-premises network | BGP or static |
| Direct Connect gateway | A dedicated link through Direct Connect | BGP |
| Peering | A transit gateway in another Region or account | Static routes only |
| Connect | A third-party SD-WAN appliance over GRE | BGP |
This chapter focuses on VPC attachments. The key point at this level is that one hub serves cloud and on-premises networks with the same routing model.
Limits and behaviors to know before you design
- Subnets in an attachment. A VPC attachment uses one subnet per Availability Zone. The transit gateway places a network interface in each chosen subnet. A VPC can reach the transit gateway only from AZs where you chose a subnet. If an instance sits in an AZ with no attachment subnet, its traffic to the gateway is dropped.
- Per-VPC attachment. You can attach a given VPC to a transit gateway only once.
- No overlapping CIDRs. If two attached VPCs have overlapping ranges, the gateway cannot choose between them. Propagation of the second range conflicts with the first. A later chapter covers workarounds.
- Route limits and bandwidth. Each VPC attachment supports a burst of up to 50 Gbps per AZ, and a transit gateway route table has a quota on routes. Check the current quotas in the Service Quotas console, because AWS changes them.
- Security groups do not reference across VPCs. Security group rules can reference a security group in a peered VPC, but not across a transit gateway. Use CIDR ranges in your rules instead.
- Cost. You pay an hourly charge per attachment plus a charge per gigabyte processed. A later chapter covers this in detail.
Common errors
These are the problems you will most likely see in your first transit gateway.
- Attachment is
availablebut pings time out. The VPC subnet route table has no route to the other VPC's CIDR with the transit gateway as target. Routing in the transit gateway alone is not enough. - Traffic works one way only. The destination VPC has no route back to the source CIDR. Check both directions.
- No route in the TGW route table. The attachment was never associated, or the destination attachment never propagated its CIDR. With defaults disabled, nothing is created for you.
- Works from one AZ but not another. The attachment has no subnet in the failing AZ.
- Blocked despite correct routes. A security group or network ACL on the instance or subnet denies the traffic. Routing and filtering are separate layers.
- Overlapping CIDRs. Two attachments advertise the same or overlapping prefixes, so one route wins and traffic reaches the wrong VPC or none.
What the transit gateway does not do
A transit gateway does not expose a service. It joins networks, so any host in an attached VPC with a route and an allowed security group can open a connection to any host in another. That is the right tool when many systems need broad connectivity, and a poor one when you want to give another team access to a single API. For that, the second half of this tutorial introduces PrivateLink.
Exercise
You create a transit gateway with default association and propagation disabled, attach two VPCs (10.0.0.0/16 and 10.1.0.0/16), and add VPC route table entries for each other's CIDR pointing at the gateway. Pings between instances still fail. Name two things in the transit gateway itself that you must still configure.
Show answer
You must associate each attachment with a transit gateway route table, so traffic from that attachment is looked up somewhere. You must also get routes into that table, either by enabling propagation from each attachment or by adding static routes, so the table knows which attachment reaches 10.0.0.0/16 and which reaches 10.1.0.0/16. With defaults disabled, none of this happens automatically.
Exercise
A transit gateway has attachments for VPC A in three AZs, but the attachment has subnets in only two of them. An instance in the third AZ cannot reach VPC B, while instances in the other two can. Why, and how do you fix it?
Show answer
The transit gateway has no network interface in the third AZ, so traffic from that AZ cannot enter the attachment. Add a subnet from the third AZ to the attachment, for example with aws ec2 modify-transit-gateway-vpc-attachment and --add-subnet-ids.