Designing High Availability Architecture with AWS S3 & CloudFront Using AWS CLI

Description:

🔰 Create High Availability Architecture with AWS CLI 🔰

🔅The 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.

What will we exactly do in this practical?

We will work on AWS EC2 Instance. We will attach a new EBS Volume with it. We will install httpd on the EC2 Instance.

Then, we will mount the Apache Web Server folder on the new EBS Volume. We will create a HTML Page then, and add an image as well in the image attribute. The image would be stored into AWS S3.
And at last, The image in the bucket in AWS S3 will be treated as the origin domain name for the CloudFront. The CloudFront would give us an intelligent link that would load on the User’s browser and store the image in the nearest Edge Location Cache. Next time, a user will visit the image again, image would be fetched from the Cache instead of S3.

This would result in lower latency and would be highly available. This is the concept used by almost all the companies so that they are always near to the user.

What is AWS S3?

Amazon Simple Storage Service (Amazon S3) is an object storage service that offers industry-leading scalability, data availability, security, and performance.

What is AWS CloudFront?

Amazon CloudFront is a fast content delivery network (CDN) service that securely delivers data, videos, applications, and APIs to customers globally with low latency, high transfer speeds, all within a developer-friendly environment.

Practical:

  1. Launch an AWS EC2 Instance using the following command:
aws ec2 run-instances --image-id ami-0947d2ba12ee1ff75 --instance-type t2.micro --count 1 --subnet-id subnet-f002ae96 --security-group-ids sg-09e38a0d7cb048036 --key-name datanode
AWS Console showing a new Instance running

2. Create a new EBS Volume.

aws ec2 create-volume --volume-type gp2 --size 1 --availability-zone us-east-1b

3. Attach the EBS Volume to the new Instance created.

aws ec2 attach-volume --volume-id vol-0c16c700a53c27544 --instance-id i-036ffa5fa387859dc --device /dev/xvdf
EBS Volume

4. Login to the EC2 Instance using ssh

ssh -i datanode.pem ec2-user@3.235.53.88

5. Install httpd server on the Instance and start httpd server

yum install httpd

systemctl start httpd

6. Create a partition in the EBS Volume created

fdisk /dev/xvdf

7. Format the partition and mount the /var/www/html/folder to the EBS Volume.

mkfs.ext4 /dev/xvdf1

mount /dev/xvdf1 /var/www/html/

8. Confirm whether it’s mounted or not

df -h

9. Create a S3 Bucket.

aws s3api create-bucket — bucket cloudmanan — region us-east-1

10. Copy a file (like image) into the S3 bucket

aws s3 cp my-pic.jpg s3://cloudmanan/pic1.jpg

11. Make the bucket and the image public

aws s3api put-object-acl — bucket cloudmanan — key pic1.jpg — acl public-read

12. Create a CloudFront distribution

aws cloudfront create-distribution — origin-domain-name cloudmanan.s3.amazonaws.com — default-root-object pic1.jpg

13. Copy the CloudFront link into the html file

14. Open the Web Page on Browser:

Hope you liked it!!
Thank you

Data Science, Big Data, Cloud Computing