🔰 Create High Availability Architecture with AWS CLI 🔰

Yash Sankhla
3 min readJul 8, 2021

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 an S3 bucket.
- Finally, place the Cloud Front URL on the
web app code for security and low latency.

Step 1 - Creating Instance

aws ec2 run-instances --image-id <ur-ami-id> --instance-type <instance-type> --count <choose-count-eg.-1> --subnet-id <ur-subnet-id> --security-group-ids <ur-sg-id> --key-name <ur-key-name-with-path>

Input
Output

Step 2 - Creating EBS Volume & Attaching It to Instance

aws ec2 create-volume --volume-type <volume-type> size <size> --availability-zone <ur-az>

Input — Volume Creation
Output
Output

ec2 attach-volume --instance-id <ur-inst-id> --volume-id <ur-vol-id> --device <device-name-eg-/dev/sdf>

Input — Volume Attachment
Output

Step 3 - Installing httpd software

yum install httpd -y

systemctl start httpd

systemctl enable httpd

Step 4 - Creating partition, formatting & mounting it to /var/www/html

mkfs.ext4 <device-name>

mount /var/www/html

For more info on partition then —> Click Here.

Step 5- Creating S3 bucket

aws s3 mb s3://<bucket-name>

Step 6- Let’s test up to here…..

Put some HTML code with an image reside in s3 in the bucket created previously to /var/www/html with file name index.html & navigate to the instance public IP to see results. My results are here:

Image from S3

Step 7- Creating Cloud Front Origin for CDN

aws cloudfront create-distribution --origin-domain-name <s3-bucket-name>.s3.amazon.com

Input
Output

Step 8- Now, get some ☕☕ as it will take some time to setup at all Edge Locations.

Hope so your are making your tea, in the middle just check URL is up or not.

Step 9- After the CDN is up then change the URL in index.html to CloudFront URL

Final Output From CF

Hope you enjoy & understand How I created the setup so thanks for Reading guys.

Keep Learning😉🙂

--

--

Yash Sankhla

ARTH Learner * Cloud * AI/ML/DL/NN * DevOps * Hadoop * Web Dev * DB-SQL & NoSQL* DSA * RHEL 8 * Image Processing * Languages — C, C++, Python