Intro #
VPC Peering is needed when you want to connect two different VPC each other. Mostly used for cross-department in SDLC.
In this example, I will connect between two VPCs Developer and Finance, and each VPC attached to different EC2 intance.
Check Private IP range of an EC2 instance #
Make sure to check local IP address range for both Developer and Finance instances.
- Navigate to the Developer instance, select and click on the
Subnet ID
- In the subnet section, select your subnet name and click on the
Route table
- In the route table section, select your route table and click
Routes
tab - Take a notes on the private IP address range for the Developer instance
Creating VPC Peering #
- Go to the
VPC
menu via console, selectPeering connections
, then clickCreate peering connection
button - Enter your peering details such as:
- Name: Developer <> Finance
- VPC ID (Requester): Select the Developer VPC and check the local IP address range of the VPC
- VPC ID (Accepter): Select the Finance VPC and check the local IP range of the VPC
- Tags: Name => Developer <> Finance
- Confirm click the
Create peering connection
- On the peering details, you can see the Status is Pending
- Click
Actions
menu and selectAccept request
and confirm again (The Status of peering become Active)
Adding VPC Peering to Subnet Route Table #
This must be done on EC2 servers for both Developer and Finance.
Here I will configure the Developer instance.
Back to the EC2 instance and select Developer instance details, then
Subnet ID => Route table => Routes
(like the first step)Click
Edit routes
to add new routes for VPC peeringClick
Add route
with the following:- Destination: Enter local IP address range for the Finance instance
- Target: Peering connection and select your VPC Peering that you’ve created
- Save changes
Now move to the EC2 instance and select the Finance instance. Then, do the same as on top, but make sure to enter the IP address range of the Developer instance in the Destination.
Allow ICMP/Ping between EC2 Instances #
In this example, I will allow ping to the Finance instance from the Developer instance.
- Click on the EC2 and select the Finance instance
- Click on the
Security
tab and then clickSecurity groups
section - In the
Inbound rules
tab, clickEdit inbound rules
- Now
Add rule
- Type: Custom ICMP- IPv4
- Source: Enter the range IP address of Developer instance
- Save rules
Test VPC Peering #
- Connect to your EC2 instance (Developer) via Session Manager or SSH
- You can now ping to the local IP of the Finance instance