VPC with servers in private subnets and NAT.
Tags: loadbalancer, autoscalinggroup, bastianhost, vpcandsubnets
Published: 2023-08-01 10:21:17


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



Aws Project reference link: 
https://docs.aws.amazon.com/vpc/latest/userguide/vpc-example-private-subnets-nat.html 

Youtube reference: https://youtu.be/FZPTL_kNvXc 

What we will Learn in this Project:
1.VPC, SUBNETS, ROUTE TABLE, SECURTY GROUPS, INTERNET GATEWAYS, NAT GATEWAYS
2.Creation of Launch Template.
3.Creation of Auto Scaling Group
4.Creation of Target Groups
5.Working with the Load balancer
6.Working on Bastian Host
 
_**

## Create VPC & MORE:
**_


1. Search for VPC then click on create VPC and choose VPC and more.
2. Enter VPC name and select number of  availability zones and and no of subnets and NAT gateways 1per AZ and VPC end point is not required here.

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





**_

## Create Launch Template:
_**


1.	Enter the name of LT and description the choose AMI then select key pair then don’t include subnets then create a new SG then select VPC then enter SG inbound rules we can allow all traffic or we can allow only custom TCP 80 and accessible from anywhere (0.0.0.0) also SSH port is anywhere (0.0.0.0)


**_

## Create Auto Scaling group:
_**


• Click on Ash and name of the ASG and select LT then next choose VPC and select only PRIVATE SUBNETS. Why is it because we are creating this ASG for ec2 instances in private subnets.
• LOAD BALANCER we are not creating/adding why we don’t want load balancing in this private subnets region.
• Desired capacity is 2 and min is 1 and max is 4 then scaling is select NONE then create ASG.
	

**_

## Install Application in the one Private Server only:
_**


 1st create one public instance and we have login to that instance and we have to create a .pem file in that server because we want to jump into private instance we need .pem file
`ssh -i venkyy.pem ubuntu@10.0.135.154`
 here it is the command to log into the private server. Ofter login create one basic html file and then we have to use the below command for running python server by using python3

```
<!DOCTYPE html>
<html>
<body>
<h1>This is my 1st aws project to demonstrate in private subnet</h1>
</body>
</html>
```

`python3 -m http.server 8000` 

(#here port 8000 we can use anything but make sure we should create Target group by using this port and enable that port in the Security Group. )
 the above mentioned command we have to run in the private instance only. ofter creating index.html file in the private server. Ofter running the python our application will run. we can terminate the process by ctrl+C
 Now we will not install application in one more private instance why because we are checking the request like if the request goes to App installed private instance we should get the response if our response goes to uninstalled private instance we should get error. That is what we are checking here
 OR We can install install application in both servers also in the index.html make some difference like this 1t server and in the 2nd private instance index.html create like this is 2nd server.

**_

## Create Target Groups:
_**



	Click on create TG enter name and HTTP 80 by default but we run python application on 8000 port so here we have to choose HTTP 8000 (what ever the port we used to run the python app rhat port we have to use here) and vpc and add 2 private instances and include as pending. Then create.



**_

## Creating Load Balancer:
_**


 Here we have to create load balancer for routing the load to servers when ever the load increase.
 Load balancer here we have to create in public subnet.
 To create load Balancer 1st we have to create Target Groups.
 Click on Creating Load Balancer and enter name of the LB and choose Internet facing and then choose VPC and choose public-subnets only in the both availability zones.
 Select SG that SG should have SSH and TCP 8000 & 80 traffic inbound
 Ofter creating the load balancer copy the DNS of load balancer and hit on chrome.

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