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

Deploy a webserver

Let’s start with Step by Step :-

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.
aws ec2 create-security-group --description “Allow 22 & 80 “ — group-name “myweb” “sg-07f4f6d47aac53c9c”
aws ec2 authorize-security-group-ingress --group-name “myweb” — protocol “tcp” — port 22 — cidr “0.0.0.0/0”
aws ec2 authorize-security-group-ingress --group-name "myweb" --protocol "tcp" --port 80 --cidr "0.0.0.0/0"
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
aws ec2 create-volume --availability-zone "ap-south-1b
" --size 1
It will provide you FULL DETAIL about volume
aws ec2 attach-volume --device "xvdb" --instance-id "i-0ac9dd067ed8b860d"  --volume-id "vol-007d85bbbb2ad295d"
It will give you info about EBS Volume .
ssh -i my.pem ec2-user@instance_public_ip
now you landed to the ec2-instance.
ec2-user@ip-172-31-15-177~]$sudo su
login with root user
[root@ip-172-31-15-177 ec2-user]# yum install httpd-y
Package install for deploy web server on the top of instance.
[root@ip-172-31-15-177 ec2-user]# systemctl start httpd
service start
[root@ip-172-31-15-177 ec2-user]# systemctl status httpd
check status : active
[root@ip-172-31-15-177 ec2-user]# fdisk -l
[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 .
[root@ip-172-31-15-177 ec2-user]# mkfs.ext4 /dev/xvdb1
format the volume
[root@ip-172-31-15-177 ec2-user]# mount /dev/xvdb1 /var/www/html/
mount done
aws s3 mb s3://webmy
here you go to that folder where you put your data which you want to upload on webserver.
aws s3 cp . s3://bucket_name --recursive --acl public-read
data uploaded
aws cloudfront create-distribution --origin-domain-name bucketname.s3.amazomaws.com
it will give you all info about cloud front .
Finally guys , my webpage is deployed on the top of the AWS instance.

THANKS FOR EVERYONE TO READ THIS ARTICLE !!🤗

--

--

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

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

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