Deploy the servers in private SN. Servers receive requests through the LB and connect to the internet by using a NAT gateway.

Venkateswara Reddy - Dec 9 '23 - - Dev Community

This Blog demonstrates how to create a VPC that you can use for servers in a production environment. To improve resiliency, you deploy the servers in two Availability Zones, by using an Auto Scaling group and an Application Load Balancer. For additional security, you deploy the servers in private subnets. The servers receive requests through the load balancer. The servers can connect to the internet by using a NAT gateway. To improve resiliency, you deploy the NAT gateway in both Availability Zones.

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

Create VPC & MORE:

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

Image description

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>


Enter fullscreen mode Exit fullscreen mode

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 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 soe 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

. . . . . . . . . . . . .