Networking and Content Delivery · Topic 2 of 6

VPC Peering, Transit Gateway and Endpoints

Connect VPCs with peering or Transit Gateway, and reach AWS services privately using gateway endpoints, interface endpoints and PrivateLink.

  • 5 min
  • Includes a diagram
In a nutshell
  • Peering links two VPCs, needs non overlapping CIDRs, and is not transitive.
  • Both sides need routes to the peering connection.
  • Transit Gateway is a hub for many VPCs and on premises networks, and routing is transitive.

What it is

Real environments use many VPCs, and they must talk to each other and to AWS services without crossing the public internet. AWS gives you several options, and the exam is about picking the right one for the size and shape of the design.

The options are VPC peering, AWS Transit Gateway, gateway endpoints, interface endpoints and PrivateLink.

VPC A10.0.0.0/16peeringVPC B10.1.0.0/16VPC AspokeTransit GatewayhubVPC Cspoke

How it works

VPC peering

A peering connection links two VPCs, in the same or different accounts and Regions. Traffic stays on the AWS network and uses private IP addresses.

  • The CIDR blocks must not overlap.
  • Peering is not transitive. If A peers with B and B peers with C, A cannot reach C through B.
  • You must add routes in both VPCs' route tables that point to the peering connection.
  • Security groups and network ACLs must allow the traffic.
  • One side requests, the other accepts.

Peering is simple and cheap for a few VPCs, but the number of connections grows quickly as VPCs are added.

Transit Gateway

VPC peering links VPC A to B and B to C but gives no route from A to C through B, while a transit gateway hub connects VPC A, B, C and an on premises VPN attachment with transitive routing controlled by its route tables. AWS Transit Gateway is a regional hub. You attach VPCs, VPN connections, Direct Connect gateways and other transit gateways (peering) to it, and it routes between them. Because every attachment connects to the hub, routing is transitive.

Transit gateway route tables control which attachments can talk to which. You can separate production from development by using different route tables. Each VPC subnet that needs the hub also needs a route to the transit gateway in its own route table.

FeatureVPC peeringTransit Gateway
TopologyOne to oneHub and spoke
Transitive routingNoYes
ScaleFew VPCsMany VPCs and networks
CostNo hourly charge for the connectionHourly attachment charge and data processing charge
Routing controlVPC route tablesTransit gateway route tables

Gateway endpoints

A gateway endpoint gives private access to Amazon S3 and Amazon DynamoDB only. It is a target in route tables, using a prefix list for the service, and there is no charge for the endpoint itself.

# AWS CLI: create a gateway endpoint for S3
aws ec2 create-vpc-endpoint \
  --vpc-id vpc-0123456789abcdef0 \
  --service-name com.amazonaws.us-east-1.s3 \
  --route-table-ids rtb-0priv1

Traffic from private subnets to S3 then stays on the AWS network and does not use a NAT gateway. An endpoint policy can limit which buckets are reachable.

Interface endpoints and PrivateLink

An interface endpoint puts an elastic network interface with a private IP address in your subnet. It uses AWS PrivateLink and works for many AWS services, such as Systems Manager, Secrets Manager and CloudWatch, and for services offered by other accounts. Private DNS can make the normal service name resolve to the endpoint's private address.

Interface endpoints cost per hour and per gigabyte of data. They use security groups, so you control who can reach them.

Endpoint typeServicesHow it is reachedCost
GatewayS3, DynamoDBRoute table entryNo endpoint charge
InterfaceMany services and PrivateLink servicesENI with private IPHourly and data charges

Exposing your own service

With PrivateLink, a service provider puts a Network Load Balancer in front of the service and publishes an endpoint service. Consumers create an interface endpoint to it. Traffic is one way, from consumer to provider, and the VPC ranges may overlap, because no routing between the VPCs is needed.

Consumer VPCinterface endpointPrivateLinkProvider VPCNLB and service

Choosing

  • Two VPCs that need full connectivity: peering.
  • Many VPCs, on premises links, and central control: Transit Gateway.
  • Private access to S3 or DynamoDB at lowest cost: gateway endpoint.
  • Private access to other AWS services, or to one service in another VPC: interface endpoint and PrivateLink.
  • Overlapping CIDR ranges with a need to share one service: PrivateLink.
Exam tip

"S3 or DynamoDB without internet access and without extra cost" is a gateway endpoint. "Any other service privately" is an interface endpoint.

What to remember for the exam

  • Peering links two VPCs, needs non overlapping CIDRs, and is not transitive.
  • Both sides need routes to the peering connection.
  • Transit Gateway is a hub for many VPCs and on premises networks, and routing is transitive.
  • Gateway endpoints exist only for S3 and DynamoDB, and are free.
  • Interface endpoints use PrivateLink, ENIs and security groups, and have hourly and data charges.
  • PrivateLink allows one way access to a service, and overlapping CIDRs are not a problem.
  • Endpoint policies can restrict what an endpoint allows.
  • Peering works across accounts and Regions.

Common mistakes

Assuming peering is transitive. Traffic cannot pass through a peered VPC to a third one.

Adding a route on one side only. Both route tables need an entry for return traffic.

Using a gateway endpoint for other services. It exists only for S3 and DynamoDB.

Forgetting private DNS on interface endpoints. Without it, the service name resolves to the public address.

Peering VPCs with the same CIDR. Overlap prevents the connection.

Watch out

A gateway endpoint works through route tables only for the subnets associated with them. A subnet whose route table lacks the entry still goes through the NAT gateway or the internet.

Check yourself

Answer these three.

  • A full mesh of 10 VPCs needs central routing. What fits?

    AWS Transit Gateway, because it is a transitive hub and avoids many peering connections.

  • Which endpoint type gives private access to S3 at no endpoint charge?

    A gateway endpoint.

  • How can a provider share a service with consumers whose CIDRs overlap?

    Use AWS PrivateLink with a Network Load Balancer endpoint service.

Topic 2 of 6 in Networking and Content Delivery

Test yourself on Networking and Content Delivery

The full AWS SOA-C03 question bank has 850 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by AWS. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.