🔰 Creating A High Availability Architecture with AWS CLI | EC2 | Cloudfront | EBS | S3🔰

In the above article, I am going to create a very basic high availability architecture on the top of the AWS cloud using AWS CLI. The main aim of this task is to integrate different services of AWS cloud such as EC2, S3, Cloudfront, EBS, etc.

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

Here are the basic steps required to set up the AWS CLI:

> Download and Install the AWS CLI program
> Create an IAM user in AWS.
> Run the ‘aws configure’ command and provide access key, secret key, and the region.
> And now, you are all set to use the AWS CLI.

aws ec2 run-instances --image-id ami-081bb417559035fe8 --instance-type t2.micro --count 1 --subnet-id subnet-f676729e --security-group-ids sg-0e09e226f6f5b1c24 --key-name ansiblekey

And the instance has been launched:

Next Step: Creating an EBS volume:

aws ec2 create-volume --volume-type gp2 --size 10G--availability-zone ap-south-1a

The volume is created as well:

Next step: Attaching the volume to the ec2 instance:

aws ec2 attach-volume --volume-id vol-0e95f89b7cb1d316e --instance-id i-0fdf14a16ee5f8784 --device /dev/sdf

Volume attached:

Next Step: Creating a partition of the newly attached volume, formatting it and then mounting it. For this, we have to go inside our instance and perform the above steps:

Use the above command to install the Apache webserver”

yum install httpd -y

Next Step: Mount the volume

Now, let’s create an S3 bucket using AWS CLI:

aws s3api create-bucket --bucket mycf123 --region ap-south-1 --create-bucket-configuration LocationConstraint=ap-south-1

For ease, I have given the public access to the bucket and the object.

Next Step: Upload an object in the bucket:

aws s3 cp g1.png s3://mycf123

Next Step: Creating a Cloudfront distribution:

aws cloudfront create-distribution --origin-domain-name cf123.s3.amazonaws.com

Now, the final step is to create a webpage that will contain dynamic content (code part) from the external EBS and the static content (image) from the CloudFront.

In the above image, you can see that the /var/www/html directory is mounted to the external EBS. And we have the CloudFront URL in the index.html file as well.

The final step is to start the web service:

systemctl start httpd; systemctl enable httpd

And hence, the entire setup has been ready with the help of AWS CLI.

Thank you for reading. Hope you liked the article.

For any queries, DM me on LinkedIn:

I am an active learner who likes to challenge every problem with a can-do mindset in order to make any idea a reality.

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