AMAZON VPC - PEERING & ROUTE 53.
Published: 2022-04-06 15:51:00


## **VPC PEERING**

- A VPC peering connection is a network connection between two VPCs that allows you to direct traffic between them using private IPv4 or IPv6 addresses.

- Instances in any VPC can communicate with each other as if they were on the same network.

- You can create a pairing connection between your own VPCs or with a VPC from another AWS account.

- VPCs can be in different regions (also known as cross-region VPC pairing connection).

- A VPC pairing connection helps you make data transfer easier. For example, if there is more than one AWS account, you can pair the VPCs between those accounts to create a file sharing network. You can also use a VPC pairing connection to allow other VPCs to access the features you have in one of your VPCs.

## **Lets Create this setup**

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

## **LAB WORK**
Lets create a VPC in Mumbai region.
VPC name :- VPC-1
Ipv4 CIDR :- 10.0.0.0/16

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

Create a public subnet inside that VPC
Subnet name :- Public-subnet
AZ :- ap-south-1a
Ipv4 CIDR :- 10.0.1.0/24

Create a private subnet inside that VPC
Subnet name :- private-subnet
AZ :- ap-south-1b
Ipv4 CIDR :- 10.0.2.0/24

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

Create an Internet Gateway and attach it with VPC

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

Create Route tables for public and private subnet with subnet association and attach internet gateway routes to public subnet.

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

Launch a public instance inside a public subnet and private instance inside a private subnet.[Disable public IP of that private instance]

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

_

> You are not able to ssh inside this private server [Due to no internet & no public ip].
> You can only ssh it only when you are inside any public server present in the same network area.
_


Create a target group and attach it with load balancer.

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

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

Host a simple website inside that public server for testing purpose.

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

You can't SSH into the private instance because there is no internet.


Create a VPC inside N.Virginia.
Lets create a VPC in Mumbai region.
VPC name :- VPC-B
Ipv4 CIDR :- 11.0.0.0/16

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

Create a public subnet inside that VPC
Subnet name :- Public-subnet-B
AZ :- ap-south-1a
Ipv4 CIDR :- 11.0.1.0/24

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

Create an Internet Gateway and attach it with VPC

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

Create Route tables for public subnet with subnet association and attach internet gateway routes to public subnet.

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

Launch a public instance inside that public subnet.

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

Create a target group and attach it with load balancer.

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

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

Host a simple website inside that server for testing purpose.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lfffquawit8ljrfi42a2.png)
[Make sure that load balancer dns also showing this website as it is attached to this instance] 

Now Lets create VPC Peering
Go to Mumbai region
Click on peering connection
Name:-mumbai-peering
Select your local VPC
Copy the VPC id of N.v and paste in another region place.
create connection
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hwsv2y3t8wngt9rrydl4.png)

Accepct the request in another region

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

Now Go to routes and inside Mumbai region routes paste the N.v VPC id and vice versa.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b2svgvhg1biusoq0biwk.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xh2tp60rbl8p5cri5axm.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cq8yskie2uqeu8lebzm0.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m0s9wxtnro0ud54uda4d.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q28d9xlfp9aap9eetle5.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pl4tamvtguu6zdai7nzn.png)

VPC Peering setup completed...now You can access mumbai server through N.v server. 

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

## **ROUTE 53**

- Amazon Route 53 is a highly available and scalable Domain Name System (DNS) web service. You can use Route 53 to perform three main functions in any combination: domain registration, DNS routing, and health check. If you choose to use Route 53 for all three functions, perform the steps in this order:

**1.  Domain Registration & Domain Hosting**
Your site needs a name, such as example.com. Route 53 allows you to register a name for your website or web application, known as a domain name.

**2. Route Internet traffic to your domain resources**

When a user opens a web browser and informs their domain name (example.com) or subdomain name (acme.example.com) in the address bar, Route 53 helps connect the browser to the website or web application.

**3. Check the health of your resources (Health Checks)**

Route 53 sends automatic requests over the Internet to a resource, such as a web server, to verify that it is accessible, available, and functional. You can also choose to receive notifications when a feature becomes unavailable and choose to divert Internet traffic from unhealthy resources.

**Now the Question is if there is any problem/issue inside that mumbai server then how to routes all traffic to another region,so that we will never face any down time in future.**
- We can route the traffic using failover routing policy.

**Lab Work**
Go to freenom or any domain registration site and purchase a domain.
Put that domain name inside the hosted zones of rout53.

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

Copy and paste the name servers.

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

Create Two Health check

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

Then click on create records
Go for failover routing policies.
Put mumbai region as primary and N.v as secondary.

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


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

Now type systemctl stop httpd inside your Mumbai public server, it will route traffic to N.v server.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3gh13fl8sljuny3fzurp.png)
[In case if there will be any problem in Mumbai server then it will route the traffic to N.V server. ] 

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

It will automatically routes the traffic to Mumbai server when it will be healthy.