Sub topic 13
Using both in a hub-and-spoke design
This chapter assumes you know how transit gateway route tables, VPC route entries, and PrivateLink endpoint services work from earlier chapters. Here you combine them in one design.
Why combine them
Transit Gateway and PrivateLink solve different problems. Transit Gateway gives network-level reachability between VPCs. PrivateLink exposes one service without joining networks. A hub-and-spoke design uses each where it fits:
- Transit Gateway carries general traffic between spokes, shared tooling, and on-premises networks.
- PrivateLink publishes specific services to consumers that should not see the rest of your network.
A worked layout
Suppose you run three VPCs in one Region:
- A prod spoke (10.0.0.0/16) and a dev spoke (10.1.0.0/16).
- A shared-services VPC (10.2.0.0/16) that hosts DNS, logging, and an internal API behind a Network Load Balancer.
- A partner account that must call only the internal API.
Routing for the internal spokes
Create two transit gateway route tables, one for spokes and one for shared services.
- Associate prod and dev attachments with the spoke table.
- Associate the shared-services attachment with the shared table.
- Propagate the shared-services CIDR into the spoke table, so spokes can reach it.
- Propagate the prod and dev CIDRs into the shared table, so replies can return.
- Do not propagate prod into dev, or dev into prod.
The spokes now reach shared services but not each other. This is the segmentation pattern from the earlier chapter. Each spoke VPC also needs a route to 10.2.0.0/16 with the transit gateway as the target.
Publishing the API to the partner
The partner should not be attached to the transit gateway. Attaching it would give it a network path into your address space. Instead, publish the NLB as an endpoint service and allow only the partner's account.
aws ec2 create-vpc-endpoint-service-configuration \
--network-load-balancer-arns arn:aws:elasticloadbalancing:us-east-1:111122223333:loadbalancer/net/my-svc/0123456789abcdef \
--acceptance-required
aws ec2 modify-vpc-endpoint-service-permissions \
--service-id vpce-svc-0123456789abcdef0 \
--add-allowed-principals arn:aws:iam::444455556666:rootThe partner creates an interface endpoint in its own VPC, and you accept the connection. The partner's traffic reaches only the NLB's listeners.
Why this split works
| Need | Use | Reason |
|---|---|---|
| Prod and dev reach shared tooling | Transit Gateway | Many-to-one network routing |
| Partner calls one API | PrivateLink | No route to your other networks |
| Partner CIDR overlaps yours | PrivateLink | Endpoint traffic does not depend on matching routes |
Exercise
A new vendor VPC must call only your billing API, and its CIDR overlaps with prod. Should you attach it to the transit gateway? Explain.
Show answer
No. Publish the billing API's Network Load Balancer as an endpoint service, allow the vendor's account, and let the vendor create an interface endpoint. A transit gateway attachment gives network-level reachability and cannot route between overlapping CIDRs. PrivateLink exposes only the service and does not need matching routes.