Deploying webserver by creating a High Availability Architecture using AWS CLI

Task Description 
- Webserver configured on EC2 Instance
- Document Root(/var/www/html) made persistent by mounting on EBS Block Device.
- Static objects used in code such as pictures stored in S3
- Setting up Content Delivery Network using CloudFront and using the origin domain as S3 bucket.
- Finally place the Cloud Front URL on the webapp code for security and low latency

🤩So guys this is my new article which give you some high level idea about HIGH AVAILABILITY ARCHITECTURE .

I Hope you will get knowledge from this article.

so ! why are you waiting ?

LOOK FOR WHAT’S AHEAD & IT WILL TAKE YOU FAR BEYOND

Deploy a webserver

Let’s start with Step by Step :-

Step 1 : First create a key pair which help you to launch the instance for create a new key pair use below mention command .

aws ec2 create-key-pair --key-name “my”  --query “KeyMaterial” --output text > my.pem
Command for create new key-pair and convert into .pem format which help you to login with ssh protocol.

Step 2 : Create a Security Group for your instance using the below mention command .

aws ec2 create-security-group --description “Allow 22 & 80 “ — group-name “myweb” “sg-07f4f6d47aac53c9c”

Step 3 : Allow Port 22 for accessing the ssh protocol which help you to login with instance remotly.

aws ec2 authorize-security-group-ingress --group-name “myweb” — protocol “tcp” — port 22 — cidr “0.0.0.0/0”

Step 4 : Allow port 80 to access the Webserver.

aws ec2 authorize-security-group-ingress --group-name "myweb" --protocol "tcp" --port 80 --cidr "0.0.0.0/0"

Step 5 : Now its time to launch ec2-instance with the help upper created new key-pair & security group.

aws ec2 run-instances --image-id " ami-0e306788ff2473ccb" --instance-type "t2.micro" --key-name "my" --security-group-id "sg-07f4f6d47aac53c9c"  --count 1 --subnet-id "subnet-35b4df79"
Launch ec2-instance

Step 6 : Now instance will be ready but we want to attach extra volume for saving the data persistence .

why attached extra EBS VOLUME�🤔

If by chance instance will be crashed or destroy then the data should not be lost.

for creating new volume using below mention command.

aws ec2 create-volume --availability-zone "ap-south-1b
" --size 1
It will provide you FULL DETAIL about volume

Step 7 : Now EBS Volume created , to put some data into the EBS volume we need to attached EBS Volume with ec2-instance . use below mention command.

aws ec2 attach-volume --device "xvdb" --instance-id "i-0ac9dd067ed8b860d"  --volume-id "vol-007d85bbbb2ad295d"
It will give you info about EBS Volume .

Step 8 : Now setup will completed EBS Volume attached with instance . Now we have to login with the help of ssh protocol .use below mention command.

ssh -i my.pem ec2-user@instance_public_ip
now you landed to the ec2-instance.

Step 9 : Now you login with ec2-user but you need to login with root user to access all the permission of the instance. for this use below mention command.

ec2-user@ip-172-31-15-177~]$sudo su
login with root user

Step 10 : Now install the Apache Webserver on the top of the instance using below mention command.

[root@ip-172-31-15-177 ec2-user]# yum install httpd-y
Package install for deploy web server on the top of instance.

Step 11 : Now start the httpd service by using below mention command.

[root@ip-172-31-15-177 ec2-user]# systemctl start httpd
service start

Step 12 : Check the service started or not use below mention command.

[root@ip-172-31-15-177 ec2-user]# systemctl status httpd
check status : active

Step 13 : See how many volumes your instance has, using the below-mentioned command.

[root@ip-172-31-15-177 ec2-user]# fdisk -l

Step 14 : Now you have to do the partition of the volume to use it . for this you have to go inside the disk console . using the below-mentioned command.

[root@ip-172-31-15-177 ec2-user]# fdisk /dev/xvdb
Here first press n to create new partition enter , enter , enter then press p for partition then press enter and enter and enter . write w to save it .

Step 15 : Partition has taken place so now you have to format the volume using the below-mentioned command.

[root@ip-172-31-15-177 ec2-user]# mkfs.ext4 /dev/xvdb1
format the volume

Step 16 : After format the volume mount it by using command with directory /var/www/html where we put our code of web page .

[root@ip-172-31-15-177 ec2-user]# mount /dev/xvdb1 /var/www/html/
mount done

Step 17 : Now create a new bucket to save all the static data of the web page using below mention command .

aws s3 mb s3://webmy
here you go to that folder where you put your data which you want to upload on webserver.

Step 18 : now after create S3 Bucket , copy all the static data by using below mention command .

aws s3 cp . s3://bucket_name --recursive --acl public-read
data uploaded

Step 19 : After copying the static data, I want to distribute this data to all Edge Locations of AWS. For distributing the data to all the edge locations we have to use the CloudFront service of AWS. So use the below-mentioned command to create the distribution.

aws cloudfront create-distribution --origin-domain-name bucketname.s3.amazomaws.com
it will give you all info about cloud front .

Step 20 : After deploying the static data at all the edge locations we have to just copy and paste the domain name of distribution at the place of data which you are using as static and have copied inside the S3 bucket as I have done in my webpage code which is mentioned in below screenshot. for this go to the /var/www/html folder .

Step 21 : Now browse the webpage with publicIP//file_name.html .

Finally guys , my webpage is deployed on the top of the AWS instance.

I tried to explain as much as possible. Hope You learned Something from here. Feel free to check out my LinkedIn profile and obviously feel free to comment.

LINKEDIN PROFILE LINK :- https://www.linkedin.com/in/jatin-lodhi-9230571a7/

THANKS FOR EVERYONE TO READ THIS ARTICLE !!🤗

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jatin Lodhi

Jatin Lodhi

I am an IT Enthusiast, who is passionate about exploring/learn all the latest technologies from research perspective.