Code Monkey home page Code Monkey logo

project-aws-vpc-with-public-private-subnet-'s Introduction

VPC with public-private subnet in production

Services used

-VPC, EC2, Automatic Scaling Group, Launch Templates, Security Group, Linux, Load Balancer.

Description

- This project demonstrates how to create a VPC that can be used for server in a production environment

- To improve resiliency, Deployed the server in two availability Zones, by using an Auto Scaling group and an Application Load Balancer.

- For additional security, deployed the server in private subnet.

- The servers receive request through the load balancer. The server can connect o the internet by using a NAT gateway. To improve resiliency, deployed the gateway in both Availability Zones.

Overview

- The VPC has public subnets and private subnets in two Availability Zones.

- Each public subnet contains a NAT gateway and a load balancer node.

- The servers run in the private subnets, are launched and terminated by using an Auto Scaling group, and receive traffic from the Load Balancer.

- The servers can connect to the internet by using the NAT gateway.

1

Lets start with creating a VPC (Virtual Private Cloud).

Required Configuration for VPC

  • Select option - VPC and more
  • Name the VPC
  • Number of Availability Zones - 2 (for High Availability)
  • Number of Public Subnet - 2
  • Number of Private Subnet - 2
  • Number of NAT Gate - 1 per AZ (For masking of application IP addresses)
  • VPC endpoints - None (As Database is not required – 2 Tier Application)

Screenshot (248) Screenshot (251) Screenshot (252)

Hit Create VPC And wait for this Outcome

Screenshot (253) Screenshot (254)

Now we will Create Auto Scaling Group and for creating Auto Scaling Group we need to create Launch template as Launch template is used as reference for creation of instances in future during downtime

  • Search for EC2
  • Search for Auto Scaling Group
  • Click on Create Launch Template

Screenshot (255)

  • Name the Template
  • Provide Description

Screenshot (256)

  • Choose Operating System as Ubuntu (For Linux based applications)

Screenshot (257)

  • Choose Instance Type (As per Requirements) I am using t2 micro (free tier applicable)
  • Key Pair (For Login Authentication)

Screenshot (258)

  • Click Network Settings (For Creating Security Group with Inbound Rules)
    • Select create security group
    • Name the security group
    • Provide description
    • select VPC ( select VPC just created )
    • security rule 1 = Type ssh, Port 22, Source Type anywhere (for SSH login)
    • security rule 2 = Type Custom TCP, Port 8000, Source Type anywhere
  • Hit Create Screenshot (259) Screenshot (260)

After creation of Launch Template we will create Auto Scaling Group

Step 1 -

  • Name the auto scaling group
  • Select the launch template we have just created
  • Hit next

Screenshot (261) Screenshot (262)

Step 2 –

  • Choose VPC last created

Screenshot (263)

  • Choose the private subnet of both the AZ ( As application needs to be in private )
  • Hit next

Screenshot (264)

Step 3 –

  • I have not attached any load balancer at Auto Scaling Group private subnet for applications
  • Health check is Okay
  • Hit next

Step 4

  • Desired capacity – 2
  • Minimum capacity – 1
  • Maximum capacity – 4 (if traffic increases for applications it can expand up to 4 machines)
  • Scaling policies – None
  • Hit next

Screenshot (265) Screenshot (266)

Step 5

  • Here we can use SNS for notification about machine if added or terminated (I have not used SNS in this project)
  • Hit next

Screenshot (267)

Step 6

  • Here we can use tags for using this Auto Scaling Group in future (I am using tags in this project )
  • Hit next

Step 7

  • Review all the configurations of tha Auto Scaling Group
  • Hit Create Auto Scaling Group

Screenshot (268)

Now check EC2 instance if Auto Scaling Group have created 2 instances in the selected subnet at step 2 of Auto Scaling Group Creation

After checking the subnets, we will install the applications in both the private instances

Bastion Host

For installing applications, we need to connect the private application server. To connect the private server, we need to create Bastion Host ( As public IP is not present to SSH the private application server ) For creating Bastion Host, we will Create an EC2 instance

  • Name instance Bastion Host
  • Select the image ubuntu (For Linux based applications )

Screenshot (269)

  • Instance type – t2 micro
  • Select Key pair to ssh connect the Bastion Host

Screenshot (270)

  • Network setting - select the same VPC as created above
  • Add security group which allow SSH connect to Bastion Host
  • Enable assign public IP
  • Hit Launch Instance

Screenshot (272)

Copy the key pair (pem file) from local computer to the bastion server using the SCP command

  • scp -i /path/key-pair-name.pem /home/ubuntu/key.pem ubuntu@IP ADDRESH:/home/ubuntu

Screenshot (273)

Connect to the Bastion Host through ubuntu terminal using SSH command

  • ssh -i /path/key-pair-name.pem instance-user-name@instance-public-ip-address

After establishing the connection with Bastion Host, we will connect to the private application server
Check if the pem file is present or not by using ( ls )command

Screenshot (275)

Connect to the private application server through Bastion Host using SSH command

  • ssh -i /path/key-pair-name.pem instance-user-name@instance-private-ip-address

Screenshot (276)

Install the application

  • Make a simple vim file ( vim index.html )and write this simple html code <! DOCTYPE html>

My AWS PROJECT to demonstrate apps in private subnet

  • then run the python command at port 8000

  • python3 -m http.server 8000

Screenshot (277)

Create Application Load Balancer which works with HTTP & HTTTPS - ( Level 7 Load Balancer )

  • Select application load balancer

Screenshot (278)

  • Name the load balancer
  • Select – Internet facing
  • Select IPV4

Screenshot (279)

  • Select VPC which is created above
  • Select both the Availability Zones only with public subnet
  • Select Security Group with Port 80 from anywhere

Screenshot (281)

For Load Balancer - Create target Group

  • Select instance

Screenshot (283)

  • Name the target group

Screenshot (284)

  • Select HTTP port 8000
  • Hit next

Screenshot (285)

Select the instance as target for load balancer that were created above by Auto Scaling Group

Screenshot (287)

Port for selected instance – 8000 Click – Include as pending below

  • Hit Create Target Group

Screenshot (288)

After creation of the target group

Add this target group to the Load Balancer

  • Select protocol – HTTP
  • Open port – 80
  • Select Default action – VPC created above

Screenshot (289)

Hit create Load Balancer

Screenshot (290)

Now Go to the Load Balancer – If its showing error for port 80 then change the security group and allow HTTP ,TCP,80,Anywhere

Screenshot (291) Screenshot (292)

Now Copy the DNS name link and paste on your Browser to Look your HTML page

Screenshot (293)

My AWS PROJECT to demonstrate apps in private subnet

Screenshot (294)

project-aws-vpc-with-public-private-subnet-'s People

Contributors

themannu avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.