Lesson 2 of 3 Private and Hybrid Connectivity

Connecting VPCs with Peering and AWS Transit Gateway

This lesson explains how VPC peering connects pairs of VPCs and how AWS Transit Gateway connects many VPCs and on-premises networks through a hub.

Learning outcomes

After completing this lesson, you will be able to:

  • Explain VPC peering and its limits.
  • Describe transit gateway attachments and route tables.
  • Segment networks with Transit Gateway.

VPC peering

A VPC peering connection connects two VPCs, in the same or different accounts and Regions, so instances communicate using private IP addresses over the AWS network. One side requests and the other accepts. Both VPCs' route tables need routes to the other's CIDR through the peering connection, and security groups must allow the traffic (security groups in a same-Region peered VPC can be referenced). Peering is non-transitive: if A peers with B and B with C, A cannot reach C through B, and A cannot use B's internet gateway, NAT gateway or VPN. CIDRs must not overlap. Peering has no hourly charge, and data transfer within an AZ over peering is free, making it cost-effective for a few high-volume connections. DNS resolution of public hostnames to private IPs across the peering can be enabled.

Select all that apply

Peering requirements

Exam skills 5.1.2 · 5.3.1

Identify what a working VPC peering connection needs.

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

AWS Transit Gateway

A transit gateway is a Regional hub to which attachments connect: VPCs (through ENIs in a subnet per AZ), Site-to-Site VPN connections, Direct Connect gateways, Transit Gateway Connect (SD-WAN) and peering with transit gateways in other Regions. Transit gateway route tables control routing: each attachment is associated with one route table (which routes its outbound traffic), and attachments propagate their routes into route tables, or static routes are added. Multiple route tables segment traffic, for example production VPCs that cannot reach development VPCs but all can reach shared services. VPC route tables must also send the destination CIDRs to the transit gateway. Transit Gateway is shared across accounts with AWS RAM, is charged per attachment-hour and per GB processed, and supports Flow Logs.

VPC peering
TopologyPoint-to-point, non-transitive
ScaleMesh becomes unmanageable with many VPCs
On-premises connectionsNo
SegmentationBy which peerings exist
CostData transfer only
Transit Gateway
TopologyHub and spoke, transitive through route tables
ScaleThousands of attachments
On-premises connectionsVPN and Direct Connect attachments
SegmentationMultiple TGW route tables
CostPer attachment-hour and per GB

The following diagram shows three Transit Gateway route tables that separate production from development.

Segmenting with Transit Gateway route tables. Production attachments use the prod route table, which receives propagations from shared services and the VPN only. Development attachments use the dev table, with shared services only. Shared services and the VPN use the shared table, which receives everything, so production and development never reach each other.
Adding a production VPC means associating it with prod and propagating it to shared.
Scenario questions

Peering or Transit Gateway?

Exam skills 5.1.2

Choose the connectivity option for each requirement.

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

Segmenting with Transit Gateway

A company connects 20 VPCs and its data centre. Production VPCs must reach shared services and on premises but not development VPCs. The network team creates three TGW route tables: prod, dev and shared. Production attachments are associated with prod, which has propagations from shared services and the VPN only; development attachments use dev, with propagations from shared services only; shared services and the VPN use shared, which receives propagations from everything. Each VPC's route table sends 10.0.0.0/8 to the transit gateway.

Check yourself

Can VPC A reach VPC C through VPC B over peering?

Show answer

No. Peering is non-transitive; A and C need their own peering or a transit gateway.

Exam Tips

Remember for the exam

  • VPC peering is non-transitive and requires non-overlapping CIDRs and routes on both sides.
  • Peered VPCs cannot use each other's IGW, NAT or VPN.
  • Transit Gateway: associate each attachment with a route table and propagate or add routes.
  • VPC route tables must point to the transit gateway too.
  • Multiple TGW route tables segment environments.