Skip to content
Visual explainer 4h to learn 5 steps

Peering, Transit Gateway, VPN & Direct Connect

Choose a connectivity option for multi-VPC and on-premises scenarios.

By Invicly Tech, , in AWS Solutions Architect – Associate. About 13 minutes to read.

Topic 11 of 34

In short

VPC peering links two VPCs directly, while Transit Gateway acts as a central hub for many VPCs and on-premises networks. Site-to-Site VPN gives an encrypted tunnel over the internet in minutes, and Direct Connect gives a private, consistent dedicated link that takes weeks to provision.

Think of it like this: Peering is a private footbridge between two buildings; Transit Gateway is the central train station.

Explained simply

Sooner or later, networks need to talk to each other: two VPCs, fifty VPCs, or AWS and your office data center. AWS offers several ways to connect them, and each fits a different size and need.

VPC peering is a direct link between two VPCs. It is simple and cheap, but it does not pass traffic on: if A peers with B and B peers with C, A still cannot reach C. With many VPCs, the number of links explodes. Transit Gateway fixes that by acting as a central hub that every VPC plugs into once.

To reach your office or data center, Site-to-Site VPN builds an encrypted tunnel over the normal internet. You can set it up in an afternoon, but speed and latency depend on the internet. AWS Direct Connect is a private cable from your network into AWS. It is steady and fast, but takes weeks to arrange.

Many companies use both: Direct Connect for daily traffic, and a VPN as a cheap backup in case the cable fails. On the exam, the words "quickly", "encrypted", "consistent latency" and "many VPCs" tell you which option the question wants.

Press Play on a diagram to walk through it one step at a time.

MapConnectivity options
Connect networks
  • VPC to VPC
    • VPC peering: few VPCs
    • Transit Gateway: many VPCs
    • PrivateLink: one service
  • On-premises to AWS
    • Site-to-Site VPN
    • Direct Connect
    • DX plus VPN backup
  • Users to AWS
    • Client VPN
CompareVPN vs Direct Connect
Site-to-Site VPN
  • IPsec over the internet
  • Set up in minutes
  • Variable latency
  • Bandwidth capped per tunnel
  • Encrypted by default
Direct Connect
  • Private dedicated connection
  • Weeks to provision
  • Consistent latency
  • Dedicated ports up to 400 Gbps
  • Add MACsec or VPN to encrypt
ComparePeering vs Transit Gateway vs PrivateLink
VPC peering
  • One-to-one VPC link
  • Not transitive
  • No hourly fee
  • No overlapping CIDRs
Transit Gateway
  • Hub for VPCs, VPN and DX
  • Transitive with route tables
  • Per attachment and per GB fees
  • No overlapping CIDRs
PrivateLink
  • One service, one direction
  • Consumer creates an endpoint
  • Overlapping CIDRs are fine
  • Provider needs an NLB

In depth

VPC peering rules

A peering connection links exactly two VPCs, in the same or different Regions and accounts. One side requests, the other accepts, and then both sides must add routes pointing the other VPC's CIDR at the peering connection (pcx-). Security groups must also allow the traffic; in the same Region, you can reference the peer's security groups.

The limits are strict. CIDRs must not overlap. Peering is not transitive. There is no edge-to-edge routing either: a VPC cannot use its peer's internet gateway, NAT gateway, VPN, Direct Connect or gateway endpoint.

Peering has no hourly charge and no bandwidth bottleneck, since it uses the existing AWS network. You pay normal data transfer, and traffic between peered VPCs in the same AZ is free. A full mesh of n VPCs needs n times (n minus 1) divided by 2 connections, so 10 VPCs need 45 and 20 need 190. That is where Transit Gateway takes over.

  • No overlapping CIDRs
  • Not transitive, no edge-to-edge routing
  • Add routes on both sides
  • No hourly charge

Transit Gateway in depth

A Transit Gateway is a Regional router. You attach VPCs (one subnet per AZ), Site-to-Site VPNs, Direct Connect gateways, SD-WAN appliances through Connect attachments, and other Transit Gateways through peering, including across Regions. Routing is transitive: anything attached can reach anything else, if the route tables allow it.

Transit Gateway route tables give you segmentation. Each attachment is associated with one route table, which decides where its traffic can go, and attachments propagate their routes into chosen tables. A common design keeps Prod and Dev separate while both reach a shared services VPC and on-premises.

Share one Transit Gateway across accounts with AWS Resource Access Manager. You pay per attachment per hour and per GB processed, so for two VPCs with heavy traffic, peering can be cheaper. For VPN attachments, equal-cost multipath (ECMP) spreads traffic across tunnels for more bandwidth.

MapSegmenting with Transit Gateway route tables
Transit Gateway
  • Prod route table
    • Associated: prod VPCs
    • Routes: shared VPC, on-premises
  • Dev route table
    • Associated: dev VPCs
    • Routes: shared VPC only
  • Shared route table
    • Associated: shared services VPC
    • Routes: prod, dev, on-premises
  • On-prem route table
    • Associated: VPN and DX
    • Routes: prod and shared VPCs

Site-to-Site VPN mechanics

On your side, a router or firewall is defined in AWS as a customer gateway. On the AWS side, the VPN terminates on a virtual private gateway attached to one VPC, or on a Transit Gateway to reach many. Every VPN connection has two IPsec tunnels ending in different AZs, so AWS maintenance or an AZ problem does not drop you, provided your device brings up both tunnels.

Routing is static, where you type the prefixes, or dynamic with BGP, where routers exchange routes and fail over automatically. Prefer BGP. Each standard tunnel carries up to about 1.25 Gbps. For more, attach the VPN to a Transit Gateway and use ECMP across several connections. Accelerated VPN, available on Transit Gateway, enters the AWS network at the nearest edge location for steadier performance.

For individual remote users rather than whole offices, AWS Client VPN provides a managed, OpenVPN-based service.

SequenceA VPN connection with two tunnels
Office router
Tunnel 1 (AZ a)
Tunnel 2 (AZ b)
  1. 1IKE and IPsec up, BGP session
    Office router to Tunnel 1 (AZ a): IKE and IPsec up, BGP session
  2. 2IKE and IPsec up, BGP session
    Office router to Tunnel 2 (AZ b): IKE and IPsec up, BGP session
  3. 3Advertise 192.168.0.0/16
    Office router to Tunnel 1 (AZ a): Advertise 192.168.0.0/16
  4. 4Advertise VPC 10.0.0.0/16
    Tunnel 1 (AZ a) to Office router: Advertise VPC 10.0.0.0/16
  5. 5Traffic flows on tunnel 1
    Office router to Tunnel 1 (AZ a): Traffic flows on tunnel 1
  6. 6Tunnel 1 down: BGP moves traffic
    Office router to Tunnel 2 (AZ b): Tunnel 1 down: BGP moves traffic

Direct Connect in depth

Direct Connect is a physical cross-connect at a Direct Connect location, a data center where AWS has routers. Dedicated connections come in 1, 10, 100 and 400 Gbps. Hosted connections from AWS partners range from 50 Mbps to 25 Gbps and are faster to get. Lead time is typically weeks.

Over the link you create virtual interfaces (VIFs). A private VIF reaches VPCs through a virtual private gateway or a Direct Connect gateway. A transit VIF reaches Transit Gateways through a Direct Connect gateway. A public VIF reaches AWS public endpoints, such as S3, over the private link. A Direct Connect gateway is a global object, so one connection can reach VPCs in many Regions.

Direct Connect is private but not encrypted. Use MACsec on supported dedicated connections, or run an IPsec VPN over it. For resilience, AWS recommends connections at two separate locations, or two at each of two locations for maximum resiliency.

FlowPath of a Direct Connect packet
  1. 1
    Your router

    In your data center.

  2. 2
    DX location

    Cross-connect to AWS router.

  3. 3
    Virtual interface

    Private or transit VIF, BGP.

  4. 4
    DX gateway

    Global, links many Regions.

  5. 5
    VGW or TGW

    Into one VPC or many.

Choosing connectivity for exam scenarios

Look for the deciding words. "Two or three VPCs, low cost" suggests peering. "Dozens of VPCs", "hub and spoke", "transitive" or "simplify management" suggests Transit Gateway. "Expose one application to other VPCs or customers" suggests PrivateLink. "Connect the office quickly" or "encrypted over the internet" suggests Site-to-Site VPN. "Consistent latency", "large data transfers" or "dedicated private connection" suggests Direct Connect.

Combinations are common. "Direct Connect plus encryption" means a VPN over Direct Connect or MACsec. "Highly available, cost-effective hybrid" often means Direct Connect with a VPN backup. When both paths advertise the same prefix, AWS prefers Direct Connect routes over VPN routes, so failover to VPN happens only when Direct Connect drops.

Watch for traps: peering never reaches a peer's VPN or internet gateway, and Direct Connect cannot be ready "this week".

Learn it in 5 short steps

About 50m each. Track them with a timer in your plan.

  1. 1
    Connect two VPCs with peering~50m
  2. 2
    Connect many VPCs with Transit Gateway~50m
  3. 3
    Set up Site-to-Site VPN concepts~50m
  4. 4
    Compare Direct Connect with VPN~50m
  5. 5
    Choose connectivity for exam scenarios~50m

Key points

  • Peering is not transitive and CIDRs must not overlap.
  • Transit Gateway gives transitive hub-and-spoke routing across VPCs, VPN and Direct Connect.
  • For DX resilience use two connections at separate locations, or a VPN as backup.
  • Direct Connect alone is not encrypted; run IPsec VPN over it or MACsec when required.

Key terms

Tap a card to flip it. 0/5 known

Examples

Growing from peering to Transit Gateway

A company starts with three VPCs and one office. Step 1: three peering connections (3 times 2 divided by 2) and a VPN on the main VPC are enough. Step 2: the office cannot reach the other two VPCs, because peering has no edge-to-edge routing. Step 3: after growth to 15 VPCs, a full mesh would need 105 peerings. Step 4: create a Transit Gateway, share it with RAM, attach every VPC and the VPN, and point each VPC's route for 10.0.0.0/8 at the Transit Gateway. Step 5: remove the old peerings. Now any VPC can reach the office, and new VPCs need one attachment each.

bash
TGW=$(aws ec2 create-transit-gateway --description hub \
  --options AmazonSideAsn=64512,DefaultRouteTableAssociation=enable,DefaultRouteTablePropagation=enable \
  --query TransitGateway.TransitGatewayId --output text)
aws ec2 create-transit-gateway-vpc-attachment --transit-gateway-id $TGW \
  --vpc-id $VPC --subnet-ids $PRIV_A $PRIV_B
aws ec2 create-route --route-table-id $PRIV_RT \
  --destination-cidr-block 10.0.0.0/8 --transit-gateway-id $TGW

Resilient hybrid link for a bank

A bank needs steady 10 Gbps to AWS, encryption, and no single point of failure, at reasonable cost. Step 1: order two 10 Gbps dedicated Direct Connect connections at two different Direct Connect locations. Step 2: enable MACsec on both, which meets the encryption requirement without VPN throughput limits. Step 3: create transit VIFs to a Direct Connect gateway associated with the Transit Gateway. Step 4: add a Site-to-Site VPN to the same Transit Gateway as a last-resort backup. Step 5: because AWS prefers Direct Connect routes over VPN routes for the same prefix, traffic stays on Direct Connect and only moves to the VPN if both connections fail. Test failover by shutting down a BGP session in a maintenance window.

Quick reference

  • Peering: two VPCs, not transitive, no edge-to-edge routing, no overlapping CIDRs
  • Full mesh of n VPCs needs n(n-1)/2 peerings: 10 VPCs = 45
  • Transit Gateway: Regional hub, route tables for segmentation, share with RAM
  • Every Site-to-Site VPN connection has 2 tunnels in different AZs; use BGP
  • Standard VPN tunnel: about 1.25 Gbps; scale with ECMP on Transit Gateway
  • Direct Connect dedicated: 1, 10, 100, 400 Gbps; hosted: 50 Mbps to 25 Gbps
  • Direct Connect is not encrypted: add MACsec or IPsec VPN on top
  • Same prefix on DX and VPN: AWS prefers the Direct Connect route

Common mistakes

  • Expecting VPC A to reach C through B when A-B and B-C are peered.
  • Choosing Direct Connect when connectivity is needed this week.

Quick quiz

Pick an answer to see if you're right and why.

Question 1

1VPC A peers with VPC B, and B has a NAT gateway. Can instances in A use it for internet access?

Question 2

2Prod and Dev VPCs are attached to one Transit Gateway. Both must reach shared services but never each other. How?

Question 3

3A regulator requires encryption on a new Direct Connect link. What satisfies it?

Question 4

4A team needs office-to-VPC connectivity by tomorrow, encrypted, at low cost. What fits?

Question 5

5Why should an on-premises VPN device bring up both tunnels of a VPN connection?

0/5 answered

Practice exercises

Try each one yourself first. Use the hint if you get stuck, then compare with the solution.

  1. Exercise 1easy

    Peer two VPCs in your account (10.0.0.0/16 and 10.1.0.0/16) and add the routes so they can talk.

  2. Exercise 2medium

    A company has 8 VPCs today and expects 30 next year, plus two data centers. Compare the number of connections needed with peering and with Transit Gateway.

  3. Exercise 3hard

    Design connectivity for: 20 VPCs in two Regions, one data center needing 5 Gbps steady throughput, encryption required, and survival of any single link failure.

Check yourself

Answer in your head, reveal, then be honest with yourself.

Feel confident about this topic?

Frequently asked questions

Is VPC peering free?
There is no charge to create or keep a peering connection. You pay data transfer, and traffic between peered VPCs within the same AZ is free.
How long does Direct Connect take to set up?
Usually several weeks, because a physical cross-connect must be arranged. Hosted connections from partners can be quicker.
Can Transit Gateway connect VPCs in different Regions?
Yes, by peering Transit Gateways across Regions. Traffic between them travels over the AWS global network and is encrypted.
What is the difference between a virtual private gateway and a Transit Gateway?
A virtual private gateway is the VPN or Direct Connect endpoint for a single VPC. A Transit Gateway is a hub that connects many VPCs and on-premises links together.

Go deeper

ShareXLinkedInWhatsApp