Connecting VPCs through VPC Peering

Connecting VPCs through VPC Peering

What is VPC Peering?

VPC Peering is a networking connection between two VPCs that enables you to route traffic between them using private IP addresses. Instances in either VPC can communicate with each other as if they were within the same network, allowing for seamless data sharing and management across VPCs.

No alt text provided for this image

Key Benefits of VPC Peering:

  • Cost-Effective: VPC Peering is typically less expensive than setting up a VPN or other networking solutions.

  • Performance: Provides low-latency, high-bandwidth connectivity between VPCs.

  • Security: Communication is private and does not traverse the public internet, enhancing security.

  • Simplicity: Easy to set up and manage within the AWS Management Console.

Steps to Create VPC Peering Connection:

  1. Initiate VPC Peering Connection:Sign in to AWS, navigate to VPC, select Peering Connections, create a peering connection, and configure it between VPC A ( test-vpc-1) and VPC B (test-vpc-2).

    Step 1:

    Create two VPC's named as test-vpc-1 and test-vpc-2. Enter the IPv4 CIDR 12.0.0.0/16 and 13.0.0.0/16 respectively and create VPC.

    Step 2:

    Create Two subnets named as test-subnet-1 and test-subnet-2. Enter IPv4 CIDR 12.0.1.0/24 and 13.0.1.0/24 respectively and create subnet.

    Step 3:

    Create Two route tables named as test-rt-1 and test-rt-2. Select route table one by one and in actions select subnet association and select subnets as shown.

    step 4:

    Click the Subnet associations with the created route table for the Public subnet. then, click "Edit subnet associations" under Subnet associations

    Step 5:

    Create Internet Gateway and in upper green bar click attach to a VPC and select test-IGW-1 and test-IGW-2 then attach.

    Step 6:

    Go to the route table and select test-rt-1 and test-rt-2 then, Edit Route as below.

    Now, We can see that the Resource Map

  2. Accept the Peering Connection:Sign in to the account owning VPC B, navigate to VPC, find and accept the pending peering connection.

    Step 7:

    In the navigation pane, choose Peering connection. Name your Peering as test-peering-from-vpc1-to-vpc2. Select test-vpc-1 as Requestor and test-vpc-2 as Acceptor and Create Peering Connections. Then select your created peering and in right click on actions then accept the request.

  3. Update Route Tables for VPC 1:In the VPC dashboard, select the route table for VPC A, add a route to the CIDR block of VPC B, and save.

    Step 8:

    Now from navigation bar select route tables , select the test-rt-1 then click on actions and select edit route and add route in destination enter the CIDR of test-rt-2 and in target select peering connections and click on save changes.

  4. Update Route Tables for VPC 2:Select the route table for VPC B, add a route to the CIDR block of VPC A, and save.

    Step 9:

    Now add route in test-rt-2 and in destination enter the CIDR of test-rt-1 and in target select peering connection and click on save changes .

  5. Modify Security Groups for VPC 1: In the VPC dashboard, update inbound and outbound rules for VPC A’s security group to allow traffic to/from VPC B’s CIDR block.

    Step 10:

    Go in security Groups and select SG-test-vpc-1 add rule in inbound rules. In type enter All ICMP-IPv4 and in source write the both CIDR of test-vpc-1 and test-vpc-2.

  6. Modify Security Groups for VPC B: Update inbound and outbound rules for VPC B’s security group to allow traffic to/from VPC A’s CIDR block.

    Step 11:

    Go in security Groups and select SG-test-vpc-2 add rule in inbound rules. In type enter All ICMP-IPv4 and in source write the both CIDR of test-vpc-1 and test-vpc-2.

  7. Test Connectivity: Launch instances in both VPCs and verify connectivity using tools like ping or SSH.

    Step 12:

    Now all your instances are launched. Select the instance test-ec2-1 and go in security tab then add rule in inbound rules. In type enter All ICMP-IPv4 and in source write the CIDR of test-vpc-2.

    Repeat the same process for test-ec2-2 in source write the CIDR of test-vpc-1 and save rule.

    Step 13:

    Now ping the private IPv4 of test-ec2-1 from test-ec2-2 to check connectivity.

    Now ping the private IPv4 of test-ec2-2 from test-ec2-1 to check connectivity.

    Successfully Completed VPC Peering!!