0
0
AwsConceptBeginner · 3 min read

What is VPC Peering in AWS: Simple Explanation and Example

VPC peering in AWS is a way to connect two virtual private clouds (VPCs) so they can communicate privately using private IP addresses. It works like a direct network bridge between two separate networks without using the internet.
⚙️

How It Works

Imagine two separate neighborhoods, each with its own roads and houses. Normally, to visit a friend in the other neighborhood, you might have to go through a busy highway (the internet). VPC peering builds a private bridge directly connecting these two neighborhoods, so cars (data) can travel safely and quickly without leaving the local area.

In AWS, each VPC is like a private neighborhood with its own IP address range. When you create a VPC peering connection, AWS sets up a secure link between the two VPCs. This lets resources like servers in one VPC talk to resources in the other as if they were on the same local network, but without exposing traffic to the public internet.

💻

Example

This example shows how to create a VPC peering connection using AWS CLI commands between two VPCs.

bash
aws ec2 create-vpc-peering-connection --vpc-id vpc-123abc --peer-vpc-id vpc-456def

aws ec2 accept-vpc-peering-connection --vpc-peering-connection-id pcx-789ghi

aws ec2 create-route --route-table-id rtb-111aaa --destination-cidr-block 10.2.0.0/16 --vpc-peering-connection-id pcx-789ghi

aws ec2 create-route --route-table-id rtb-222bbb --destination-cidr-block 10.1.0.0/16 --vpc-peering-connection-id pcx-789ghi
Output
VPC peering connection created and accepted. Routes added to route tables for traffic between VPCs.
🎯

When to Use

Use VPC peering when you want to connect two AWS VPCs privately without using the internet. This is useful when you have multiple environments like development and production in separate VPCs but want them to communicate securely.

Common use cases include sharing resources like databases or services between VPCs, connecting VPCs in different AWS accounts, or linking VPCs in the same region for better network performance and security.

Key Points

  • VPC peering connects two VPCs privately using AWS network.
  • Traffic stays within AWS network, not exposed to the internet.
  • Works only between VPCs in the same or supported regions.
  • Does not support transitive peering (no automatic routing through a third VPC).
  • Requires updating route tables to enable communication.

Key Takeaways

VPC peering creates a private network link between two AWS VPCs.
It allows secure communication using private IPs without internet exposure.
You must update route tables to enable traffic between peered VPCs.
VPC peering is ideal for connecting environments or accounts securely.
It does not support transitive routing; each peering is direct between two VPCs.