Part 10 of 12 — 12 Hands-On AWS Projects
Introduction
Every project so far lived inside one VPC. But real companies run many VPCs — one for each team, each environment or each application — and those VPCs need to talk to each other. Today we will connect two VPCs with VPC peering, so an instance in one VPC can reach an instance in the other over a private connection, with no traffic ever touching the internet.
This is how production networks stay both connected and private.
What you will build
- Two VPCs with different, non-overlapping CIDR blocks
- One EC2 instance in each VPC, in a private subnet
- A VPC peering connection between the two VPCs
- Route table entries that send traffic between the VPCs over the peering connection
- A working ping test proving the two instances can reach each other privately
Architecture
VPC A uses the CIDR 10.0.0.0/16 and VPC B uses 10.1.0.0/16. Each VPC has one EC2 instance in a private subnet. A VPC peering connection joins the two VPCs. Each VPC's route table has an entry pointing the other VPC's CIDR block at the peering connection, so traffic flows directly between them — never through the internet.
Prerequisites
- An AWS account (free tier is enough)
- Two VPCs to create, or the default VPC plus one new VPC — the CIDR blocks must not overlap
- Two EC2 instances, one in each VPC, with a key pair for SSH access
- Security groups that allow ICMP (ping) between the instances
Steps
1. Create two VPCs with different CIDR blocks
If you are using the default VPC as VPC A, note its CIDR — usually 172.31.0.0/16. Create VPC B with a different block, for example 10.1.0.0/16. Inside VPC B, create one private subnet, for example 10.1.1.0/24. Keep the two CIDR blocks non-overlapping — peering will not work if they overlap.
2. Launch one EC2 instance in each VPC
Launch an instance in VPC A and one in VPC B, both in private subnets. Give them clear names: app-server-a and app-server-b. Attach a security group to each that allows inbound ICMP from the other VPC's CIDR block, so a ping can get through. Note down the private IP address of each instance — you will use it in the test.
3. Create the VPC peering connection
In the VPC console, go to Peering Connections and create one. Choose VPC A as the requester and VPC B as the accepter. Give the connection a name like vpc-a-to-vpc-b. Once it is created, switch to the accepter side and accept the request — the peering connection only works after both sides agree.
4. Add routes in both VPCs
A peering connection alone does nothing — each VPC needs a route telling it where to send the other VPC's traffic. In VPC A's route table, add a route: destination 10.1.0.0/16, target the peering connection. In VPC B's route table, add the reverse route: destination 10.0.0.0/16 (or the default VPC's CIDR), target the same peering connection. Now each VPC knows how to reach the other.
5. Test the private connection
SSH into the instance in VPC A and ping the private IP of the instance in VPC B:
ping 10.1.1.10
If you see replies, the peering connection works — the two private instances are talking directly, with no internet involved. Try the reverse direction too, from VPC B to VPC A. If the ping fails, check the route tables first: a missing route is the most common mistake.
What you learned
- VPC peering connects two VPCs privately, with traffic staying inside AWS
- The two VPCs must have non-overlapping CIDR blocks, or peering cannot work
- Both sides must accept the peering connection before traffic flows
- Routes in both VPCs are required — a peering connection without routes carries nothing
- A successful ping between private IPs is the simplest proof the peering works
Cleanup
A VPC peering connection itself is free, but the instances cost money. Terminate both EC2 instances when you finish, then delete the peering connection, then delete VPC B and its subnets. Keep the default VPC as it was.
Try next
In Project 11, we will build something fun with AI. You will use AWS PartyRock to create a movie search app from the Netflix landing page — no code, just a prompt.
About Cloud Messenger — Learn • Build • Visualize • Troubleshoot • Grow | cloudmessenger.in | linkedin.com/in/cloud-messenger | github.com/Cloud-Messenger | #buildwithCloudMessenger

Top comments (0)