|| EC2+EBS+S3+CloudFront || High Availability Architecture Of Web-Server via AWS CLI
5 min readNov 6, 2020

This architecture includes-
=> 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.
Let’s Start-
Step -1
- Create a key-pair :
aws ec2 create-key-pair --key-name mykey --query 'KeyMaterial' --output text | out-file -encoding ascii -filepath mykey.pem

- Show/describe key-pairs:
aws ec2 describe-key-pairs --key-names mykey


Step-2
- Create security-group :
aws ec2 create-security-group --group-name "myaws-sg" --description "Security group for instances"

- Set Inbound rules in security-group(Only allow port 22 and 80 that is for ssh and http protocol respectively) :
# aws ec2 authorize-security-group-ingress --group-name "myaws-sg" --protocol tcp --port 80 --cidr 0.0.0.0/0# aws ec2 authorize-security-group-ingress --group-name "myaws-sg" --protocol tcp --port 22 --cidr 0.0.0.0/0

- See created security group
aws ec2 describe-security-groups --group-name "myaws-sg"


Step-3
- Launch-instance via AWS CLI -
aws ec2 run-instances --image-id ami-052c08d70def0ac62 --instance-type t2.micro --key-name mykey --count 1 --security-group-ids sg-057f7e2d1574938bf

- Describe or see created instance -
aws ec2 describe-instances --instance-ids i-03a2207160a58cc68


STEP-4
- Create a EBS Volume of 1GB -
aws ec2 create-volume --size 1 --availability-zone ap-south-1b
- Attach This EBS Volume to earlier created instance -
aws ec2 attach-volume --instance-id i-03a2207160a58cc68 --volume-id vol-07fc492d082d397db --device /dev/sda2

STEP-5
- ssh into the instance via create key and user-name i.e ec2-user with public ip of instance -
ssh -i mykey.pem ec2-user@13.232.253.155


- Install apache httpd and start the service via yum command because the instance was having rhel-8 OS & preconfigured yum -
yum install httpd -y #install httpdsystemctl start httpd #start the service
- Disable SElinux — (otherwise we will not be able to access webpages)

- Create Partition of attach EBS Volume -

- format & mounting in document root folder of httpd server (/var/www/html)-
mkfs.ext4 /dev/xvdb1 #format the partitionudevadm settle #load the drivermount /dev/xvdb1 /var/www/html/ #mounting

STEP-6
- Create S3 Bucket -
aws s3 mb s3://mygallery299


- See create bucket in aws-
aws s3 ls
- Upload Object in precreated Bucket -
aws s3 cp . s3://mygallery299/ --recursive --include "*.jpg" --exclude "*.css" --exclude "*.html" --acl public-read-write


STEP-7
- Create Cloudfront Distribution —
aws cloudfront create-distribution --origin-domain-name mygallery299.s3.amazonaws.com


STEP-8
- Provide distribution Link in web pages in URL of images -


STEP-9
- Now access the web page -
- Here my gallery page came and all photos was loading from my nearest edge location of AWS and that makes this more powerful and fast .

- This Page now can access from whole world and these all photos will come from origin(s3) if first time request and after on any request pages come from the local cache of nearest edge location of client till TTL(time to live) of local cache set in cloudfront distribution…..A Great Concept of : Content Delivery Network….
DONE !!
PS : Here , I would like to thank vimal daga sir to give this task and to teach us all these concepts.. #ARTH task-6
HAPPY CLOUD LEARNING..
THANKS FOR SCROLLING…