Sub topic 7
Pointing VPC routes at the transit gateway
This chapter assumes you know CIDR blocks, subnets, and VPC route tables, and that you have already created a transit gateway, attached a VPC, and set up transit gateway route tables. Those pieces are not enough on their own. Traffic from an instance never reaches the transit gateway unless the VPC's own route table sends it there. This chapter covers that last step and the mistakes that most often break it.
Two route tables, two jobs
A transit gateway design has two layers of routing, and both must be correct for a packet to cross between VPCs.
- The VPC route table, attached to a subnet, decides whether a packet leaves the subnet toward the transit gateway.
- The transit gateway route table, associated with an attachment, decides which attachment the packet goes to next.
The transit gateway does not push routes into your VPC route tables. Propagation, which you configured earlier, only fills transit gateway route tables. Every VPC route table entry that targets the transit gateway is one you create yourself, or one you create through infrastructure as code.
The return path works the same way in reverse. VPC B needs a route for 10.0.0.0/16 that targets the transit gateway, and the transit gateway route table that VPC B's attachment uses needs a route to VPC A. A missing return route is the most common cause of one-way connectivity.
Creating the route
A VPC route that targets a transit gateway has a destination CIDR and the transit gateway ID as its target.
aws ec2 create-route \
--route-table-id rtb-0123456789abcdef0 \
--destination-cidr-block 10.1.0.0/16 \
--transit-gateway-id tgw-0123456789abcdef0This command adds one route to one route table. If a VPC has several route tables, repeat it for each table whose subnets need to reach the destination. A subnet that uses the VPC's main route table follows that table. A subnet with its own explicit association follows only that table.
You can confirm the result by listing the routes in the table.
aws ec2 describe-route-tables \
--route-table-ids rtb-0123456789abcdef0 \
--query "RouteTables[].Routes[]"A healthy entry shows TransitGatewayId and State set to active. The route's local entry for the VPC's own CIDR stays in place and always wins for traffic inside the VPC.
Prerequisites the route depends on
AWS validates a transit gateway route only partially at creation time. A few conditions must already hold, and some fail silently.
- The VPC must have an attachment to that transit gateway. Without it,
create-routecan be rejected or the route can end up in theblackholestate. - The attachment must include a subnet in the Availability Zone of the source instance. Traffic from an AZ with no attachment subnet is not forwarded locally to the transit gateway. It follows a different path or is dropped, depending on the design.
- The attachment must be in the
availablestate, notpendingormodifying.
Check the attachment before you debug routes.
aws ec2 describe-transit-gateway-vpc-attachments \
--filters Name=vpc-id,Values=vpc-0aaa1111bbb22222c \
--query "TransitGatewayVpcAttachments[].[TransitGatewayAttachmentId,State,SubnetIds]"Choosing the destination: specific CIDRs or an aggregate
You have three common ways to write the destination. Each trades simplicity against control.
| Approach | Example destination | Benefit | Cost |
|---|---|---|---|
| One route per remote VPC | 10.1.0.0/16, 10.2.0.0/16 | Precise. Only intended networks are reachable. | More entries to maintain as VPCs are added. |
| Summary route | 10.0.0.0/8 | One entry covers every private VPC in the plan. | Also sends traffic for unused ranges to the transit gateway, where it is dropped. |
| Default route | 0.0.0.0/0 | Required for centralized egress or inspection. | Replaces or competes with the internet gateway or NAT route. |
Route selection in a VPC uses the longest prefix match. A route for 10.1.0.0/16 beats a route for 10.0.0.0/8 for an address in 10.1.5.5. The local route always has the highest priority for the VPC's own CIDR, so a summary route can never hijack traffic that stays inside the VPC.
A summary route is convenient, but it has one subtle effect. If your VPC also has a peering connection or a VPC endpoint route to part of that summary range, the more specific route wins. That is usually what you want. Still, review it when you add new routes.
Prefix lists for many destinations
When many route tables need the same set of destinations, a managed prefix list keeps them in sync. You create the list once, then reference it as the route destination in each VPC route table.
aws ec2 create-managed-prefix-list \
--prefix-list-name spoke-cidrs \
--address-family IPv4 \
--max-entries 20 \
--entries Cidr=10.1.0.0/16 Cidr=10.2.0.0/16
aws ec2 create-route \
--route-table-id rtb-0123456789abcdef0 \
--destination-prefix-list-id pl-0123456789abcdef0 \
--transit-gateway-id tgw-0123456789abcdef0When you add a CIDR to the prefix list later, every route table that references it picks up the change. Keep in mind that a prefix list counts toward the route table's entry quota by its maximum size, not by the number of entries currently in it. Setting --max-entries far above what you need can use up route quota.
Route table limits and the blackhole state
A VPC route table has a default quota of 50 non-propagated routes, which you can raise through a quota request. Check the current value in Service Quotas, since limits change. A summary or prefix-list design keeps you far from that limit.
A route can show blackhole as its state. For a transit gateway target, this usually means the attachment was deleted or is no longer available. Traffic matching a blackhole route is dropped. Remove the route or restore the attachment. Do not leave stale blackhole routes in place, because they hide the real cause of a failed connection and may block a more general route from being used for that range.
Common errors
These are the problems seen most often, in rough order of frequency.
- The route exists on only one side. Both VPCs need a route to the other, and both transit gateway route tables need a path back.
- The wrong route table was edited. The subnet is associated with a different table than the one you changed. Check the subnet's association, not just the VPC's main table.
- The attachment has no subnet in the instance's AZ. Pings from one AZ work and pings from another do not.
- A security group or network ACL blocks the traffic. Routing can be correct while a security group refuses the source CIDR. Security groups can reference another VPC's CIDR but, across a transit gateway, they cannot reference that VPC's security group IDs.
- Overlapping CIDRs. If two VPCs share a range, the routes are ambiguous and the transit gateway cannot route to both. A later chapter covers this.
- Missing transit gateway route table entry. The VPC route is correct, but the transit gateway route table has no route for the destination, because propagation is off or the attachment is not associated.
Verifying a route
You can inspect what the transit gateway knows with a route search. It shows whether the destination is present and active in the table used by the source attachment.
aws ec2 search-transit-gateway-routes \
--transit-gateway-route-table-id tgw-rtb-0123456789abcdef0 \
--filters Name=type,Values=propagated,staticLook for the destination CIDR with State equal to active. If it is missing, the problem is on the transit gateway side. If it is present, return to the VPC route tables and security rules.
Exercise
Instances in VPC A (10.0.0.0/16) can send traffic to VPC B (10.1.0.0/16), but no replies come back. Both VPCs are attached, and the transit gateway route table has routes to both attachments. Name two places where the missing configuration could be, and say how you would check each.
Show answer
One place is the VPC B subnet route table, which may lack a route for 10.0.0.0/16 with the transit gateway as target. Check it with describe-route-tables on the table associated with the destination subnet. The other is the transit gateway route table associated with VPC B's attachment, which may have no route for 10.0.0.0/16 because propagation is off for VPC A or the attachment is in a different route table. Check it with search-transit-gateway-routes on that table. A security group or network ACL on the VPC A side that blocks the reply is also possible.
Exercise
A VPC route table contains the routes local 10.0.0.0/16, 10.0.0.0/8 to the transit gateway, and 10.1.0.0/16 to a peering connection. Where does traffic to 10.1.4.4 go, and where does traffic to 10.0.4.4 go?
Show answer
Traffic to 10.1.4.4 goes to the peering connection, because 10.1.0.0/16 is a longer prefix than 10.0.0.0/8. Traffic to 10.0.4.4 stays in the VPC through the local route, because the local route always applies to the VPC's own CIDR.