As you all know, VPC Peering is the private connection between two different VPC’s. In this blog, we are discussing Inter Region VPC Peering. If VPC Peering is enabled, we can connect to another VPC which may reside in another region or even in another AWS account using private IP. AWS uses existing VPC infrastructure for peering connections. The important thing to be noted while setting up a VPC peering connection is to ensure that your VPC network ranges (CIDR blocks) do not overlap. So let’s take a look at the configuration side. You have to set up two VPC’s in two different regions with subnet’s associated with it. Here, I am setting up a peering connection between Ohio and Mumbai. The IP range I am setting for Mumbai is 192.168.1.0/24 and IP Range for Ohio is 192.168.2.0/24
1. First, we have to create a peering connection. For that select the VPC service of the Mumbai region and click on the Peering connection.
2. Click on the “create peering connection”. In the newly opened window, You can see few options
- Peering connection name tag : Just a name for the peering connection
- VPC Requestor : Select the VPC that you want to connect with another one. Note the VPC ID from the VPC menu and ensure you have selected the proper one here.
- Select another VPC to peer with: Here you have three options; Account, Region, VPC.
Account : Select the option :my account” . If you want to peer with VPC in another account, you can select the other option
Region: Select the option “ another region”. Here I am using Ohio.
VPC(acceptor): The ID of the VPC in the target region. In my case, ID of the VPC in Ohio. Then click on create peering connection.
3. After creating the peering connection, a request is sent to the target VPC(Ohio) and the request should be accepted at the target VPC end. So, go to the VPC menu on our target region, here in our case Ohio and then click on the peering connection. There you can see a connection request waiting for acceptance. You can see the status as pending acceptance as shown in the screenshot. Click on the actions and select accept the request.
4. The next and most important step is to create routing rules. Route rules should be created on both the VPC’s for corresponding IP ranges. For that you can either use an existing routing table associated with VPC or you can create a new one. Click on the routing tables from VPC and click on create route table.
Provide a name for this route table and select the same VPC that we configured peering connection. Ensure the proper subnet is associated with routing table by clicking on routing table and then select subnet association.
5. Then click on routes and click on “Edit routes” There you can create a new rule. In the destination path, enter the IP range of our target VPC(Ohio) and in the target column, select “peering connection” and it will automatically fetch the peering connection ID that we have created earlier. Do the same in Ohio region. Create a routing table and add the private IP ranges of Mumbai region in the destination path of the new rule. So, we have created route rules in both regions so that the traffic is directed to both regions accordingly. In the screenshot, I am only showing the route table for Mumbai region. You can see the IP range of Ohio is added there.
6. So, that’s it. Our peering connection is ready for testing. I have virtual machines in both regions. The private IP of VM in Mumbai is 192.168.1.69. I am pinging that IP from the VM from Ohio region and you can see the ping response below.
Configuring VPC-PEERING via Powershell
We can easily configure the above steps via powershell commands. First install the aws module for powershell
Install-Module -Name AWS.Tools.Installer
Next steps is to create profile. For that we need the security key and access key.
Set-AWSCredential -AccessKey AKIA$$**KXDFOJUGF -SecretKey ZebLOW1fWY8dqr21uc7himx6KOQo3 -StoreAs sysally
The, create VPC Peering connection using New-EC2VpcPeeringConnection cmdlet. There are few parameters for this command.
-VpcId : VPC ID of the source region(Mumbai)
-PeerVpcId : VPC ID of acceptor region(Ohio)
-PeerOwnerId : The AWS account ID of the owner of the peer VPC
-PeerRegion : The region of acceptor VPC
-ProfileName : Profile created for AWS CLI.
New-EC2VpcPeeringConnection -VpcId “vpc-0ce5d25b2cc9984a6” -PeerVpcId “vpc-0638f54811b963a22” -PeerOwnerId “3**924420782” -PeerRegion us-east-2 -ProfileName sysally
Then, accept the VPC Peering request using Approve-EC2VpcPeeringConnection cmdlet
The parameters are below:
-VpcPeeringConnectionId : The VPC Peering connection ID
-Region : Region of acceptor VPC
-ProfileName : Corresponding profile name
Approve-EC2VpcPeeringConnection -VpcPeeringConnectionId “pcx-0474133f8ec03307f” -Region us-east-2 -ProfileName sysally
So the VPC peering connection is created and we can now create route rules.
New-EC2Route -RouteTableId “rtb-00700ff8ee38dd639” -DestinationCidrBlock “192.168.2.0/24” -VpcPeeringConnectionId “pcx-04713sds**ec03307f” -ProfileName sysally
-RouteTableId : ID of newly created route table.
-DestinationCidrBlock : IP range of other region
-VpcPeeringConnectionId : The ID of peering connection
-If you experience any issues first ensure the IP ranges of both region does not overlap each other.
-Check the subnet is associated with corresponding route table
-Ensure firewall rules are properly configured
Do you need any expert advice on How to configure Inter Region VPC Peering
We have an expert team to guide you
Thanks for dropping by. Ready for the next blog?