Lesson 1 of 5 VPC Connectivity and Hybrid Networking

Connecting Two VPCs with VPC Peering

This lesson explains how VPC peering connects two VPCs privately over the AWS network, so resources in each communicate with private IP addresses as if they were in one network.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe how a peering connection is created and routed.
  • Identify the limitations of peering, such as no transitive routing.
  • Decide when peering is the best choice.

How peering works

A VPC peering connection links exactly two VPCs privately, in the same or different accounts and Regions. One VPC requests the connection and the other accepts it; both must then add routes to the other VPC's CIDR range through the peering connection, because peering creates no routes by itself. Security groups can reference security groups in a peered VPC in the same Region.

Traffic between peered VPCs stays on the AWS backbone network and is encrypted between Regions. There is no hourly charge, only data transfer, which is free within an Availability Zone and charged across zones and Regions. Peering is not transitive: if VPC A peers with B and B with C, A cannot reach C through B, and the CIDR ranges of peered VPCs must not overlap.

True or false

Peering facts

Exam skills 3.4.1 · 1.2.1

Check how VPC peering works and what it cannot do.

Log in to try this activity Interactive activities are free with an account.

Limitations

VPC peering connects two VPCs, in the same or different accounts and Regions, so they communicate with private addresses. Its limitations often decide the correct exam answer. Peering is not transitive: if A is peered with B and B with C, A cannot reach C through B, so every pair that must communicate needs its own connection. The two VPCs' address ranges must not overlap, so overlapping networks cannot be peered at all.

There is also no edge-to-edge routing: a VPC cannot use its peer's internet gateway, NAT gateway, VPN connection or Direct Connect link, so peering cannot share a single path to the internet or to on premises. Finally, peering scales poorly: connecting n VPCs in a full mesh needs n × (n − 1) / 2 connections, 45 for ten VPCs, which is why larger networks use a transit gateway. The following table summarises the limitations.

LimitationConsequence
Not transitiveA peered with B and B with C does not connect A and C
No overlapping CIDRsVPCs with overlapping ranges cannot peer
No edge-to-edge routingA VPC cannot use its peer's internet gateway, NAT gateway, VPN or Direct Connect
Scales poorlyA full mesh of n VPCs needs n × (n − 1) / 2 connections

The following diagram shows why peering is not transitive.

VPC peering is not transitive. VPC A is peered with VPC B, and VPC B with VPC C, but A cannot reach C through B; A and C need their own peering connection. A full mesh of n VPCs needs n × (n − 1) / 2 connections, such as 45 for ten VPCs.
The CIDRs are illustrative. When many VPCs must communicate, a transit gateway replaces the mesh.
Fill in the value

A full mesh

Exam skills 3.4.2

Work out how many peering connections a full mesh needs.

Log in to try this activity Interactive activities are free with an account.

When to choose peering

Peering is the cheapest, lowest-latency option for connecting a few VPCs, or for high-volume traffic between two VPCs where Transit Gateway's per-GB processing charge would be significant. For many VPCs or shared on-premises connectivity, use Transit Gateway.

Worked example

Two VPCs and a lot of data

An analytics VPC copies 200 TB a month from a data VPC in the same Region. The architect compares the options for connecting just these two VPCs.

OptionCost of the traffic
VPC peeringData transfer only; free between instances in the same AZ
Transit GatewayData transfer plus a per-GB processing charge on all 200 TB

Peering is cheaper for a single high-volume connection. The architect adds routes in both VPCs and allows the analytics security group in the data VPC's security group. If more VPCs need the data later, Transit Gateway becomes the better design.

Check yourself

VPC A is peered with B, and B with C. Can A reach C through B?

Show answer

No. Peering is not transitive, so A needs its own peering connection to C, or the VPCs need a Transit Gateway.

Exam Tips

Remember for the exam

  • For a few VPCs at the lowest cost, use VPC peering.
  • Peering is not transitive and cannot connect overlapping CIDRs.
  • After creating a peering connection, add routes in both VPCs' route tables.
  • A peered VPC cannot reach the internet or on premises through its peer's gateways.