AWS-VPC (Peering Connections)
Tags: linux, devops, aws, vpc
Published: 2023-12-26 17:46:26

A VPC peering connection is a networking connection between two VPCs that enables you to route traffic between them using private IPv4 addresses or IPv6 addresses. Instances in either VPC can communicate with each other as if they are within the same network.

- VPC peering connections are limited on the number of active and pending peering connections that you can have per VPC. 

- VPC peering is a technique for securely connecting two or more virtual private clouds, or VPCs

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3rs18i03d9hs0u8ovo5f.png)

 **Step-1.** As per the above VPC Peering connection architect Create a VPC and subnet and Rout table.
 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tv65l6wpxessz0meocrj.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/86xv76qud2x8wvpv2b6q.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4c3291n11njkzt7717kw.png)

- Associate the subnet with the route table.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/50j64dusmnp25bvnuxac.png)

**Step-2.** Create the Internet Gateway and attach the VPC.
 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2w8q116xez45uanun3zo.png)

- Edit and add the Internet Gateway in the route table.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l4rp64jbia7von2noqk9.png)

**Step-3.** Create the EC2 Instance with VPC-A network settings and Publich IP enabled on the Subnet and Instance.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o1zlzv56yslr8wnvuqjn.png)

**Step-4.** As the above steps we have created another VPC, Subnet and Route table.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2lxkmnop1vw6g6lt16wf.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3n8y4c034tqaxy8nf3kf.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h0s2lkbcielg9rbzsh57.png)

- Associate the Subnet on the route table and create EC2 Instance.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pp7m0lt5ktedqpbyekm8.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pay7z24mg2wjtv9xeozn.png)

**Step-5.** We need to copy the .pem key from local and paste in the Primary VPC-A to get SSH access for another VPC-B.

- Not getting connect to the secondary VPC EC 2 Instance via SSH.

**Step-6. **Create a peering connection.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nsavth5ygc7j4p5bztr6.png)

- Accept the Peer Request.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t4vk4aey8awj8wby6pww.png)

**Step-7.** Add the Secondary IPV4 CIDR range and select the peering connection and save on the  Primary Route table.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fhc4kn0n6h407uq3yvb4.png)
**Step-8.** Add the Primary IPV4 CIDR range and select the peering connection and save on the  Secondary Route table.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8rhbhvh6xeswe2t5ofx5.png)

**Step-9.** Now we able to access the Secondary VPC EC2 Instance through the Primary VPC EC2 Instance via Peering connection.