Ravindra BagaleCourses & study guides मराठी Track your progress

AWS Transit Gateway and PrivateLink: Connect VPCs and Services Explained

Two VPCs peer easily; twenty VPCs become a mesh nightmare. Partners want private access to your service without the public internet. AWS Transit Gateway (TGW) is the hub for many VPCs; PrivateLink (interface endpoints / endpoint services) keeps traffic on the AWS network privately.

What you'll learn in this chapter

  • Why hub-and-spoke beats full mesh peering
  • What Transit Gateway and PrivateLink are
  • How to connect VPCs and expose services privately
  • Hybrid and industry patterns
  • Lab, errors, FAQ, interview

1. Everyday example first

A Bengaluru bank has VPC-app, VPC-data, VPC-shared. Instead of peering every pair, each attaches to a Transit Gateway. A fintech partner reaches the bank’s payments API through a PrivateLink endpoint service — no public ALB required for that partner path.

Why do we need this?

VPC peering does not transit; meshes do not scale. TGW routes between attachments. PrivateLink exposes a Network Load Balancer-powered service to consumers via interface endpoints — private IPs in their VPC.

  • Scale many VPC connections centrally
  • Shared services VPC without spaghetti peering
  • Private partner connectivity
  • Hybrid via VPN/DX attachments to TGW

3. What are they?

What is it?

Transit Gateway: a regional hub. Attach VPCs, VPNs, Direct Connect gateways; use route tables to isolate or share. PrivateLink: create a VPC endpoint service (NLB) or consume AWS/partner services via interface VPC endpoints (ENIs in your subnets).

PiecePlain job
TGWHub router for many attachments
VPC attachmentConnect a VPC to TGW
TGW route tableControl which attachments talk
Interface endpointENIs to reach a PrivateLink service
Endpoint serviceYour NLB-backed private service
Gateway endpointS3/DynamoDB prefix-list style (not PrivateLink ENI)
VPCs → TGW hub | Consumer VPC → Interface endpoint → Provider NLBMany networks
Controlled private paths

4. How to design without spaghetti

How to do it (step by step)

  1. Draw hub-and-spoke: shared, prod, nonprod spokes.
  2. Create TGW; attach VPCs; update subnet route tables to TGW.
  3. Use separate TGW route tables to isolate prod/nonprod if needed.
  4. For AWS APIs privately, prefer interface endpoints (or gateway for S3/DDB).
  5. To expose your SaaS privately, put NLB + endpoint service; accept consumer principals.
  6. Approve endpoint connections; least-privilege security groups on ENIs.
  7. For hybrid, attach VPN/DX to TGW; watch ASN/routes.
  8. Monitor TGW bytes and endpoint ENI costs.
  9. Document CIDR plan — overlapping CIDRs break designs.
  10. Avoid peering + TGW loops; pick a clear primary path.
# Mental model
# Consumer creates interface endpoint to vpce-svc-xxxxx
# ENIs get private IPs; SG allows app→ENI
# Provider NLB targets private IP tasks/instances
OptionWhen
VPC peeringFew VPCs, simple, no transit
Transit GatewayMany VPCs / hybrid hub
PrivateLinkExpose/consume service privately across accounts
Public API + WAFInternet clients; different threat model

6. Multi-industry notes

ISVs sell PrivateLink-connected APIs to banks who forbid public egress. Manufacturers attach plant VPCs to a TGW shared-services hub for Active Directory. Unis use TGW to connect campus firewalls via DX.

7. Industries and roles

  • Banks: private fintech connectivity
  • ISVs: PrivateLink product SKU
  • Enterprises: shared services hub
  • Hybrid IT: DX + TGW
  • Security: reduce public exposure

8. Lab: two VPCs + TGW path (account permitting)

Do this in ap-south-1 (Mumbai) unless your org forbids it. Set a budget alert first.

How to do it (step by step)

  1. Create two small VPCs with non-overlapping CIDRs.
  2. Create TGW; attach both; fix routes for a ping path.
  3. Launch tiny instances; security groups allow ICMP/SSH via SSM preferably.
  4. Ping across VPCs via TGW; capture a traceroute mindset.
  5. Optional: create an interface endpoint to a public AWS service (e.g., SSM) in one VPC.

Cleanup (stop billing)

  1. Delete instances, attachments, TGW, VPCs.
  2. Watch for leftover ENIs/endpoints.

9. Common errors and fixes

Each row is a real mistake students and juniors hit. Read the fix before you panic.

Error / symptomFix
Overlapping CIDRs across spokesRe-IP or use careful NAT patterns; prefer unique CIDRs.
Peering mesh “temporary” foreverMigrate to TGW when > few VPCs.
TGW route table shares prod↔devIsolate route tables.
Open SG on endpoint ENIsLeast ports from app SG only.
Forgot consumer approval on endpoint serviceAutomate accept for trusted principals.
Used gateway endpoint expecting PrivateLink ENIKnow gateway vs interface.
No DX/VPN redundancyTwo tunnels/connections.
Cost surprise on many AZs endpointsEndpoints are per-AZ ENIs.
Hairpin traffic inefficientlyPlace endpoints near consumers.
DNS not enabling private DNS on endpointTurn on private DNS names when appropriate.

10. Troubleshooting checklist

  1. No route: subnet RT missing TGW target.
  2. Blackhole: wrong TGW association/propagation.
  3. Endpoint pending: provider must accept.
  4. Timeouts: NLB targets unhealthy.
  5. DNS resolves public still: private DNS flag / hosted zone.
  6. Hybrid asymmetric routing: check return paths.

11. FAQ

Q. TGW free?

Hourly + data processing charges — check pricing.

Q. PrivateLink vs peering?

Service exposure vs network join.

Q. Cross-region TGW?

Peering TGWs across regions is a pattern.

Q. Replace Direct Connect?

No — DX is physical; TGW can attach it.

Q. Security?

SG/NACL + route isolation + endpoint policies.

Q. S3 via PrivateLink?

Gateway endpoint common; interface options exist for some.

12. Interview Q&A

Q. What is Transit Gateway?

Regional hub to connect VPCs/VPN/DX with route tables.

Q. Why not only peering?

No transit; mesh does not scale.

Q. PrivateLink?

Private connectivity to services via ENIs / endpoint services.

Q. Endpoint service needs?

NLB + allowed principals + connection acceptance.

Q. Hub-and-spoke benefit?

Central control, fewer connections.

Q. Overlapping CIDR problem?

Routing ambiguity; redesign CIDRs.

13. Tips in English, Marathi and Hindi

Ravindra Bagale's Tip (EN)

Draw CIDRs and trust boundaries before you click Create Transit Gateway. Networks are harder to renumber than IAM roles.

Ravindra Bagale's Tip (MR)

TGW create आधी CIDR व trust boundaries काढा. Renumber कठीण.

Tip (HI)

TGW बनाने से पहले CIDR और trust boundary बनाओ — IP बदलना IAM से कठिन है।

Try at home

  1. Sketch 3 spokes + shared hub with TGW route tables.
  2. List steps to expose an NLB service via PrivateLink.
  3. Write one overlapping CIDR failure story in two lines.

In short

  1. TGW hubs many VPCs/hybrid links.
  2. PrivateLink privately exposes/consumes services.
  3. Unique CIDRs and route isolation matter.
  4. Watch endpoint and TGW data costs.

Revision, interview and comparison cards

Revise this lesson in a few minutes. Save the cards on your phone or download them as PNG files. The QR code on each card opens this lesson.

Revision card: Transit Gateway and PrivateLink. Mesh VPC peering explodes as account count grows; SaaS over internet adds risk. Transit Gateway is a hub for VPC/on-prem routing. PrivateLink exposes services via interface endpoints privately. Attach VPCs to TGW with separate route tables; create interface endpoints for AWS/SaaS APIs. Ten app VPCs share one TGW; payments API consumed via PrivateLink, not public URL.
Revision card: Transit Gateway and PrivateLink · Download PNG · Open card page
Revision card: Segmentation and endpoints. One flat TGW route table lets prod talk to every sandbox. Separate TGW route tables isolate domains; PrivateLink keeps traffic off the public internet. Prod/shared/sandbox RT associations; enable private DNS on interface endpoints. Sandbox cannot route to prod DB TGW attachment.
Revision card: Segmentation and endpoints · Download PNG · Open card page
Comparison: Transit Gateway vs VPC peering mesh. Transit Gateway: Central hub attachments and route tables. VPC peering mesh: Each pair peered; N² complexity.
Comparison: Transit Gateway vs VPC peering mesh · Download PNG · Open card page
Comparison: Interface endpoint (PrivateLink) vs Public internet via NAT/IGW. Interface endpoint (PrivateLink): Traffic to service stays on AWS private network. Public internet via NAT/IGW: Egress to public endpoints.
Comparison: Interface endpoint (PrivateLink) vs Public internet via NAT/IGW · Download PNG · Open card page
Interview card: When prefer TGW over peering?. Many VPCs/accounts need hub-and-spoke routing without an N² peering mesh. Centralize inspection/shared services attachments. 30 VPCs → one TGW instead of dozens of peerings.
Interview card: When prefer TGW over peering? · Download PNG · Open card page
Interview card: What is PrivateLink?. Private connectivity to services via interface VPC endpoints — traffic stays off public internet. Consumer creates endpoint; provider can accept connections. Partner SaaS API only via vpce DNS, not public.
Interview card: What is PrivateLink? · Download PNG · Open card page
Interview card: Why separate TGW route tables?. Segmentation: stop prod, sandbox, and shared domains from full mesh reachability. Associate/propagate carefully; document. Sandbox RT has no route to prod attachment.
Interview card: Why separate TGW route tables? · Download PNG · Open card page
Interview card: Why enable private DNS?. Apps keep using the normal service DNS name while resolving to the endpoint ENIs. Without it you must rewrite URLs to vpce names. s3.ap-south-1.amazonaws.com resolves privately via endpoint.
Interview card: Why enable private DNS? · Download PNG · Open card page

More cards: Ravi Sir's Cards.

Practice Tasks

About this scenario

Milan Furniture is a furniture business in Milan. Giulia Rossi looks after its IT and cloud work. They count money in EUR and run their AWS resources in the eu-south-1 Region. In the tasks below you do real jobs for them using what this lesson teaches. All names, account IDs, IP addresses and numbers are made up for practice.

0 / 16

Easy Describe transit gateways

Why: Hub inventory.

What to do: Describe transit gateways.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Easy Describe VPC endpoints

Why: PrivateLink list.

What to do: Describe vpc endpoints.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Easy TGW beats many peerings — 1

Why: Scale.

What to do: Enter 1 if TGW scales better than many VPC peerings.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Easy PrivateLink no public internet — 1

Why: Private.

What to do: Enter 1 if Interface endpoints avoid public internet.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Medium Describe TGW attachments

Why: VPC links.

What to do: Describe transit gateway attachments.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Medium Describe TGW route tables

Why: Segregation.

What to do: Describe transit gateway route tables.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Medium Describe VPC endpoint services

Why: Provider side.

What to do: Describe vpc endpoint services.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Medium Describe TGW peering attachments

Why: Inter-region.

What to do: Describe transit gateway peering attachments.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Medium Allow CreateVpcEndpoint

Why: Consumer LP.

What to do: Allow ec2:CreateVpcEndpoint on *.

How:
  1. Start with { "Version": "2012-10-17", "Statement": [ ... ] }.
  2. In each statement write Effect, Action and Resource.
  3. Give only what the task needs (least privilege).
  4. Use double quotes and commas correctly. Click Check answer.

Medium Hub spoke JSON

Why: Prefer TGW hub.

What to do: JSON prefer_transit_gateway true.

How:
  1. Start from the top-level keys the task names.
  2. Indent child keys with 2 spaces (no tabs).
  3. Fill in each property with the value from the task.
  4. Click Check answer. Key order does not matter.

Medium Separate route tables segment — 1

Why: Isolation.

What to do: Enter 1 if separate TGW route tables help segmentation.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Medium Sample AZ count for HA endpoints

Why: HA.

What to do: Sample AZ count for HA interface endpoints (enter 2)?

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Hard Describe TGW VPC attachments

Why: Per-VPC.

What to do: Describe transit gateway vpc attachments.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Hard Describe VPC endpoint connections

Why: Accept/reject.

What to do: Describe vpc endpoint connections.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Hard Allow DescribeTransitGateways

Why: Viewer LP.

What to do: Allow ec2:DescribeTransitGateways on *.

How:
  1. Start with { "Version": "2012-10-17", "Statement": [ ... ] }.
  2. In each statement write Effect, Action and Resource.
  3. Give only what the task needs (least privilege).
  4. Use double quotes and commas correctly. Click Check answer.

Hard Private DNS JSON

Why: Keep private.

What to do: JSON PrivateDnsEnabled true.

How:
  1. Start from the top-level keys the task names.
  2. Indent child keys with 2 spaces (no tabs).
  3. Fill in each property with the value from the task.
  4. Click Check answer. Key order does not matter.