VPC Tutorial #4 : How to set-up VPC Peering a step-by-step guide!!
In this article we are going to set-up VPC peering between two different regions ie. us-east-1 and ap-south-1. You can follow this article make some changes if you want to create peering between same regions or with different accounts too!!
What is Inter-Region VPC Peering?
Inter-region VPC peering allows you to connect VPCs in different AWS regions, enabling the transfer of data using private IP addresses across regions. AWS handles the traffic over its backbone network, ensuring security and low latency, without requiring an internet gateway, NAT gateway, or VPN.
This feature is useful for connecting multi-region applications or data replication between regions. In our case, we will configure it to allow private subnet communication only, meaning all traffic between the VPCs will flow through private IPs, not over the public internet.
Setting Up VPC Peering Between Two VPCs in AWS
In this tutorial, we will create two VPCs, configure subnets, Internet Gateways, route tables, and then establish the peering connection between them. Architecture Overview :
follow the simple 7 step below process to master the peering connection!!
Step 1:
Creating peering-vpc-1
in us-east-1:
Navigate to the VPC Dashboard.
Click on Create VPC.
Set the CIDR block to
11.0.0.0/16
and name itpeering-vpc-1
.Click Create.
Creating Peering-vpc-2
→ ap-south-1:
Switch to the ap-south-1 region.
Repeat the process, Set the CIDR block to
12.0.0.0/16
and vpc namePeering-vpc-2
.
Step 2: Create Subnets in Each VPC
Next, we will create private subnets in each VPC.
A. For peering-vpc-1
(us-east-1):
Go to Subnets and click Create Subnet
Public-subnet-peering-vpc-1
.Choose
peering-vpc-1
.Set the CIDR block to
11.0.1.0/24
.Attached IGW internet gateway
B. For peering-vpc-
2 (ap-south-1):
Repeat the process in ap-south-1.
Set the CIDR block to
11.1.0.0/24
.s.
Step 3: Create Route Tables
To ensure traffic flows between the VPCs, we need to update the route tables in both regions.
A. Create RT in VPC-A (us-east-1):
Go to Route Tables.
create route table
rt-peering-vpc-1
.Associate RT to subnet .
modify RT as below..
B. Create RT in VPC-B (us-west-2):
Switch to us-west-2 and go to Route Tables.
create route table
rt-peering-vpc-2
.Associate RT to subnet
Modify RT for IGW and Peering connection
Step 5: Create peering connection
Create Peering connection “demo-peering-connection”
Select Requester VPC ID
Select My Account and Region Another region
Provide VPC ID (Accepter)
Hit Create peering connection.
A VPC peering connection pcx-0*****0 / demo-peering-connection has been requested.
Switch to ap-south-1 → vpc2 and accept the request
Now you need to update/modify rt (mentioned in step 3 screen shot)
Step 6: Configure Instances
For Instances in VPC-A:
Launch Ec2 instance in vpc1
Add user data →
#!/bin/bash
apt-get update
apt-get install nginx -y
echo "hostname is $(hostname)" >/var/www/html/index.html
Connect to ec2 instance by SSM/terminal.
For Instances in VPC-B:
Launch EC2 instance in vpc2.
Add user data →
#!/bin/bash
apt-get update
apt-get install nginx -y
echo "hostname is $(hostname)" >/var/www/html/index.html
Connect to ec2 instance by SSM/terminal.
Step 7: Test peering :
test “curl public ip” to each other!!
Success !!
Key Takeaways
Simplified Network Connections
"VPC Peering enables private communication between VPCs, allowing resources to talk to each other without using the internet, which enhances security and lowers latency."Essential Use Cases
"Common scenarios for VPC Peering include cross-account connections, resource sharing, and enabling secure access between separate environments like development and production VPCs."Configuration Essentials
"For VPC Peering to work correctly, both route tables and security groups must be updated to allow the traffic you want to pass between VPCs. Skipping these configurations is a common mistake."Cost and Performance Benefits
"VPC Peering doesn't have hourly costs, only data transfer fees, and it keeps data within AWS's high-speed backbone network, making it ideal for workloads needing consistent performance and low latency."
Subscribe to my newsletter
Read articles from Shivprasad Waghmare directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Shivprasad Waghmare
Shivprasad Waghmare
"Accidental DevOps Engineer | 7+ Years of Experience | Exploring AWS, Kubernetes, Terraform, Docker, Jenkins | Passionate about automating cloud infrastructure | Let’s explore the world of DevOps together!"