Sub topic 5
Attaching VPCs to a transit gateway
This chapter assumes you can read a VPC layout (CIDR blocks, subnets, route tables), know that security groups and network ACLs filter traffic differently, and can run the AWS CLI. The previous chapter introduced the transit gateway as a regional router. This chapter covers the attachment, the object that connects a network to that router.
What an attachment is
A transit gateway does nothing until something is attached to it. An attachment is the link between the transit gateway and one network. Each attachment has a type:
| Attachment type | Connects | Typical use |
|---|---|---|
| VPC | One VPC in the same Region | Inter-VPC routing |
| VPN | A Site-to-Site VPN connection | On-premises over the internet |
| Direct Connect gateway | A Direct Connect gateway | On-premises over a dedicated link |
| Peering | Another transit gateway | Cross-Region or cross-account hubs |
| Connect | A third-party appliance over GRE | SD-WAN integration |
This chapter covers VPC attachments. The other types follow the same pattern. Each is an attachment that you associate with a route table and propagate into route tables.
How a VPC attachment works
When you create a VPC attachment, you choose one subnet per Availability Zone (AZ). AWS places an elastic network interface (ENI) in each chosen subnet. These ENIs are the doorway between the VPC and the transit gateway.
Three rules follow from this design:
- You can choose only one subnet per AZ for a given attachment.
- A resource can use the transit gateway only if its AZ has an attachment subnet. Traffic from a subnet in an AZ with no attachment ENI will not reach the transit gateway, even if its route table points there.
- Traffic that enters the transit gateway from an AZ normally leaves toward the destination VPC through the ENI in the same AZ, if one exists. This keeps traffic in its AZ and avoids cross-AZ transfer charges.
Create the transit gateway and the attachment
The first command creates a transit gateway with default association and default propagation turned off. That means new attachments are not automatically placed into any route table, so you decide the routing explicitly. The second command attaches a VPC using one subnet in each of two AZs.
aws ec2 create-transit-gateway \
--description "hub" \
--options AmazonSideAsn=64512,DefaultRouteTableAssociation=disable,DefaultRouteTablePropagation=disable
aws ec2 create-transit-gateway-vpc-attachment \
--transit-gateway-id tgw-0123456789abcdef0 \
--vpc-id vpc-0aaa1111bbb22222c \
--subnet-ids subnet-0aaa1111 subnet-0bbb2222The attachment starts in the pending state and moves to available when it is ready. Check it before you do anything else:
aws ec2 describe-transit-gateway-vpc-attachments \
--filters Name=transit-gateway-id,Values=tgw-0123456789abcdef0 \
--query "TransitGatewayVpcAttachments[].{Id:TransitGatewayAttachmentId,Vpc:VpcId,State:State,Subnets:SubnetIds}" \
--output tableAn attachment in available state still carries no traffic in this setup. With default association disabled, it has no route table to consult until you associate it. The next chapter does that.
Choose attachment subnets deliberately
You can reuse an existing workload subnet, but a dedicated attachment subnet is the usual practice. A /28 subnet is enough, since the ENI needs only a few addresses.
Dedicated subnets help for these reasons:
- Network ACLs. A network ACL on the attachment subnet applies to traffic passing through the transit gateway ENI. A restrictive ACL meant for workloads can silently block transit traffic.
- Route tables. The attachment subnet's route table governs return traffic from the ENI toward your VPC. Keeping it separate avoids accidental routes.
- Address space. Small dedicated subnets leave your workload subnets untouched, so you can resize or replace them without touching the attachment.
Security groups are not attached to the transit gateway ENIs. Filtering happens at your instances' security groups and at network ACLs. If your design needs to reference security groups across VPCs, check the attachment option SecurityGroupReferencingSupport, and its current Region and attachment-type limitations, in the AWS documentation.
Attachment options
Each VPC attachment carries options you can set at creation or change later:
DnsSupportlets a resolver query resolve public DNS hostnames to private addresses across attached VPCs. It is enabled by default.Ipv6Supportenables IPv6 routing over the attachment. It is disabled by default.ApplianceModeSupportkeeps a flow on one AZ's ENI in both directions. You need it for stateful inspection appliances. A later chapter covers it.
Change options with modify-transit-gateway-vpc-attachment. You can also add or remove subnets with --add-subnet-ids and --remove-subnet-ids. While the change applies, the attachment is in the modifying state. Adding a subnet is the fix when you bring a new AZ into use.
aws ec2 modify-transit-gateway-vpc-attachment \
--transit-gateway-attachment-id tgw-attach-0123456789abcdef0 \
--add-subnet-ids subnet-0ccc3333 \
--options Ipv6Support=enableAttachments from other accounts
In a multi-account setup, the transit gateway usually lives in a shared networking account. Other accounts create attachments to it, so the owner must first share it using AWS Resource Access Manager (RAM):
aws ram create-resource-share \
--name tgw-share \
--resource-arns arn:aws:ec2:us-east-1:111122223333:transit-gateway/tgw-0123456789abcdef0 \
--principals 444455556666After the member account accepts the share (or if both accounts are in the same AWS Organization with sharing enabled), it can create a VPC attachment in its own account. The attachment's owner is the VPC's account, and the transit gateway's owner is the hub account.
The transit gateway option AutoAcceptSharedAttachments decides what happens next. When it is disable, which is the default, a shared attachment waits in pendingAcceptance. The hub owner then approves it:
aws ec2 accept-transit-gateway-vpc-attachment \
--transit-gateway-attachment-id tgw-attach-0123456789abcdef0Leaving acceptance manual gives the hub owner a checkpoint before any new network joins the routing domain. Turn on auto-accept only if you trust every account that can see the share.
Common errors
| Symptom | Likely cause |
|---|---|
| Attachment stays `pendingAcceptance` | The hub owner has not accepted a cross-account attachment. |
| Attachment is `available` but no traffic flows | The attachment is not associated with a route table, or the VPC route table has no route to the transit gateway. |
| Instances in one AZ cannot reach other VPCs, while other AZs work | That AZ has no attachment subnet. |
| Traffic is dropped only to or from some subnets | A network ACL on the attachment subnet or workload subnet blocks it. |
| Creation fails on overlapping addresses or subnet choice | Two subnets were chosen in the same AZ, or the subnet is in a different VPC. |
Also confirm that the VPC CIDR blocks of attached VPCs do not overlap. The transit gateway can hold overlapping attachments, but it cannot route between them. A later chapter covers overlapping ranges.
Exercise
A VPC spans three AZs (a, b, c). You attach it to a transit gateway using subnets in AZ a and AZ b only. The attachment is available, and routes and associations are correct. Instances in AZ c cannot reach another VPC through the transit gateway. Why, and how do you fix it?
Show answer
The attachment has no ENI in AZ c, so traffic from AZ c has no entry point to the transit gateway. Fix it by adding a subnet in AZ c to the attachment with aws ec2 modify-transit-gateway-vpc-attachment --add-subnet-ids <subnet-in-az-c>. A dedicated small subnet in AZ c is the usual choice.
Exercise
You create a transit gateway with DefaultRouteTableAssociation=disable and attach a VPC. The attachment shows available. Is the VPC now able to exchange traffic with other attachments? Explain.
Show answer
No. With default association disabled, the attachment has no associated transit gateway route table, so the transit gateway has nothing to consult for its outbound traffic. You must associate the attachment with a route table, and propagate or add routes, before traffic flows.