🔰 Create High Availability Architecture with AWS CLI 🔰

Tushar Joshi
4 min readJul 23, 2021

TASK DESCRIPTION :

✳️Create High Availability Architecture with AWS CLI

✳️The architecture includes-

🔅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 CloudFront URL on the webapp code for security and low latency.

We have already configured the ec2-instance in the previous task now we will create the entire infrastructure via aws cli in this task

This is the link for the previous task where I have covered the basics of AWS CLI and implemented it https://joshitushar210.medium.com/create-aws-services-using-cli-f0e4a8f836cf

Launching the instance:

C:\Users\hp>aws ec2 run-instances --image-id  ami-0e306788ff2473ccb  --instance-type t2.micro --subnet-id subnet-d8b1b8b0 --security-group-ids sg-08e55d1c6b7898612 --key-name awsclass2020key --count 1

2) Creating Volume:

C:\Users\hp>aws ec2 create-volume --availability-zone ap-south-1a --volume-type gp2 --size 10

3) Attaching the volume:

C:\Users\hp>aws ec2 attach-volume --volume-id vol-0585ad3cca052c5ba --instance-id  i-083734fbbb126d62c --device /dev/sdf

4) Creating Partition:

C:\Users\hp\Downloads>ssh -l ec2-user 13.235.114.61 -i awsclass2020key.pem sudo fdisk /dev/xvdf

5) Formatting Partition:

C:\Users\hp\Downloads>ssh -l ec2-user 13.235.114.61 -i awsclass2020key.pem sudo mkfs.ext4 /dev/xvdf

6) Mounting a directory:

C:\Users\hp\Downloads>ssh -l ec2-user 13.235.114.61 -i awsclass2020key.pem sudo mount /dev/xvdf /var/www/html

C:\Users\hp\Downloads>ssh -l ec2-user  13.235.114.61 -i awsclass2020key.pem sudo mount /dev/xvdf  /var/www/html

7) Installing apache web server:

C:\Users\hp\Downloads>ssh -l ec2-user  13.235.114.61 -i awsclass2020key.pem sudo yum install httpd -y

8) Start httpd and check the status:

C:\Users\hp\Downloads>ssh -l ec2-user  13.235.114.61 -i awsclass2020key.pem sudo systemctl start httpdC:\Users\hp\Downloads>ssh -l ec2-user  13.235.114.61 -i awsclass2020key.pem sudo systemctl status httpd

Here status is active as shown in the above pic

8)Login in to the instance via cli:

C:\Users\hp\Downloads>ssh -l ec2-user  13.235.114.61 -i awsclass2020key.pem

9) Webpage:

We will create a S3 bucket and insert an object into it

10) Create S3 bucket:

C:\Users\hp\Downloads>aws s3api create-bucket --bucket tus123 --region ap-south-1 --create-bucket-configuration LocationConstraint=ap-south-1

We will now make the bucket public

11)Making the bucket public:

C:\Users\hp\Downloads>aws s3api put-bucket-acl --acl public-read --bucket tus123

12) Putting object in bucket:

C:\Users\hp\Downloads>aws s3api put-object --bucket tus123 --key dir-1/lm.png --body C:\Users\hp\Downloads\lm.png

But we have only made the S3 bucket public , here the object also has its own permissions or policies so we have to make the object public which can be read on the web server rather than just download and read.

13) Making the object public

C:\Users\hp\Downloads>aws s3api put-object-acl --bucket tus123 --key dir-1/lm.png --grant-read uri=http://acs.amazonaws.com/groups/global/AllUsers

14) Creating CloudFront Distributions:

C:\Users\hp\Downloads>aws cloudfront create-distribution --origin-domain-name tus123.s3.amazon.com --default-root-object dir-1/lm.png

Here we can see that the status is in progress

Now you can see here we successfully deployed the cloud front

We have now successfully downloaded the image

Deleting the object in the bucket and then the bucket

15) Deleting S3 bucket object:

C:\Users\hp\Downloads>aws s3api delete-object --bucket tus123 --key dir-1/lm.png

16) Deleting S3 bucket:

C:\Users\hp\Downloads>aws s3api delete-bucket --bucket tus123 --region ap-south-1

🔅 🔅 Thankyou for reading 🔅 🔅

🔅 🔅 Hope it was helpful 🔅 🔅

--

--

Tushar Joshi

MLOPS Intern at Linux World || MLOPS 🧠 || DEVOPS(🐳☸👩🏻‍🍳)|| Ansible || Kubernetes|| AWS || ML || DL || Data Science || Jenkins|| Docker || RedHat Linux ||