DEV Community

Cover image for ALL YOU NEED TO KNOW ABOUT AWS VPC PEERING
Uduakabasi Umo-Odiong
Uduakabasi Umo-Odiong

Posted on

ALL YOU NEED TO KNOW ABOUT AWS VPC PEERING

OVERVIEW
Creating a network using the virtual private cloud service on AWS and connecting the network to another Virtual private cloud network to aid easy communication and exchange of resources between the networks

INTRODUCTION
I believe growing up we had friends and some of us belonged to peer groups where we had one or two people who shared similar interests. We can also apply this reasoning to networks with similar goals and objectives. To achieve these objectives resources would have to be exchanged to allow each network to play its part in the project properly. This is where you have to apply the concept of VPC peering.

VIRTUAL PRIVATE CLOUD (VPC)
Virtual Private Cloud has to do with the act of building your private network on the cloud and other resources are able to leverage the network. In other words, A virtual private cloud (VPC) is a secure, isolated private cloud hosted within a public cloud. VPC customers can run code, store data, host websites, and do anything else they could do in an ordinary private cloud, but the private cloud is hosted remotely by a public cloud provider.
It is important you know that we have other concepts under VPC which include subnets, IP Addressing, CIDR, Route Tables, Internet Gateway, NAT- Gateway and Elastic IP.

VPC PEERING
In simple terms, this is the communication between networks. The exchange of resources is easier when shared in the same network therefore creating the need for VPC peering which is the establishment of a connection whereby VPCs in different networks can share resources and communicate with each other.

PREREQUISITE

  1. An AWS account
  2. Knowledge of basic networking concepts (Subnets, Route Tables, Internet Gateway, IP Addressing, CIDR)

STEPS
i. Create a network using the AWS VPC service

  • Log into your AWS console and use the search bar to search for VPC and click on it

Image description

  • Click on Create VPC to create the first network in network peer

Image description

  • Create the second network in the peer using the same VPC service

Image description

  • select 'your VPCs' to see a list of all the VPCs you have created to be paired together

Image description

ii. Create Subnets for the networks you created (for this report we will be creating only public subnets)

  • Go to subnet under your VPC dashboard and click Create Subnet
    Image description

  • While creating the first and second subnets select the Correct VPC you are creating
    Image description

Image description

  • select 'subnets' to see a list of all the sub-networks you have created

Image description

iii. Create Route tables for both networks

  • Go to Route tables under your VPC dashboard and click Create a route table

Image description

  • Create route tables for both networks that is VPC 1 and VPC 2

Image description

  • Select route tables to get a list of all subnets you have created

Image description

iv. Create Internet Gateway for both networks because we are working with public subnets

  • Go to Internet Gateway under your VPC dashboard and click Create Internet

Image description

  • Create IGW for both networks and attach to their respective networks

Image description

  • Select internet gateway to get a list of all IGWs you have created

Image description

v.Edit Routes and subnet association

  • Select the route table you want to edit
    Image description

  • Select routes and click on edit routes

Image description

-Add route and set it to 0.0.0.0/0 then afterwards select next box, pick Interner Gateway, and finally select the IGW you created for that particular network. Save changes afterwards.

Image description

  • select subnet association and click on edit subnet association

Image description

  • Select the subnet for that route table and save the association

Image description

-Carry out these configurations on both networks to be paired together.

vi. Create Elastic Compute Cloud (Ec2) Instances for both networks

  • Go to the search bar and type Ec2 then click on Ec2

Image description

  • Click on launch instance to create your virtual server Image description

-Input the name of your server, select Amazon Linux as your Amazon machine image, and leave instance type as default because it's one of the free tier available instance types

Image description

  • Create a login key that will be used to access your server. Next, you edit network settings and link your server to the VPC you created. Then select auto-assign public IP because it is a public subnet.
    Image description

  • Leave all other settings on default then lunch instance

Image description

  • Apply all the procedures stated above and create another server for your second network

vii. VPC Peering

  • use the search bar to search for VPC and click on it

Image description

  • Scroll down the list of services under VPC and select peering connection

Image description

  • Click on create peering connection

Image description

-Select the first VPC as requester VPC

Image description

-select the second VPC as the accepter VPC. please if the accepted is in another region or another account this is where you specify the location of your second VPC

Image description

-The requester VPC will have to be accepted by the accepter VPC so there is need to configure this. Simply click on actions and select accept the peering connection request

Image description
Image description

-Edit the routes between the two VPCs. This will be done in two places for the two VPCs that are being connected

Image description

  • After selecting modify route tables, click on first route table created for first VPC and add destination. Add a route, CIDR will be the CIDR of second VPC and next select the peering connection then save changes.

Image description

-Go through similar steps for second route table
Image description

Viii. Connect your Instance to command line to test the peering connection

-Go to the first instance you created and click on it. After highlighting your instance, click on connect to connect it to the command line.
Image description

  • To connect, select EC2 instance connect and scroll down and click on connect.

Image description

Image description

  • On the command line run the command curl alongside the private IP address of your second server and the contents of the second second should come up and this means the connection is successful.

Image description

Conclusion
In conclusion, in this article we have successfully covered the concept behind VPC peering which is simply an AWS service that enables you to connect two or more VPCs in different AWS accounts or in the same AWS account and also the benefits of VPC peering which includes improved scalability, private connectivity, and ability to communicate between two different networks. If you need to communicate between two networks the most effective method is through peering the networks using the VPC peering service on AWS and to carry this out properly you should use this article as a guide.

Top comments (5)

Collapse
 
chinenye_nwafor_cf08de1a2 profile image
Chinenye Nwafor

Nicely done

Collapse
 
ovrobin profile image
Victor Robin

Insightful, nice share

Collapse
 
nora_b profile image
Nora Bassey

Nice work, well put together 👊👏

Collapse
 
bettergreat profile image
Better-Great

This was simplified in the best way possible.

Collapse
 
edidiong_umoodiong profile image
Edidiong Umo-odiong

Lovely