💥 High Availability Architecture with AWS CLI 💥

Uditanshu pandey
6 min readMar 21, 2021

Hello Readers!

In this article, we will be looking at how to create High Availability Architecture through 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 an S3 bucket.
  • Finally, place the Cloud Front URL on the web app code for security and low latency.

What is AWS?

Amazon Web Services (AWS) is a secure cloud services platform, offering computing power, database storage, content delivery, and other functionality to help businesses scale and grow. In simple words AWS allows you to do the following things- Running web and application servers in the cloud to host dynamic websites.

What is AWS CLI?

The AWS Command Line Interface (CLI) is a unified tool to manage your AWS services. With just one tool to download and configure, you can control multiple AWS services from the command line and automate them through scripts.


  • Create a key-pair.
  • Launch an EC2 instance.
  • Launch EBS and attach it to launched EC2 Instance.
  • Launch an S3 bucket and upload an object to it.
  • Create a CloudFront Distribution.
  • Configuration of Webserver in EC2 instance.

Let’s move to the task.

First, we will be setting our AWS credentials.

For this, we will use the command

aws configure 

This command will ask aws user access key, secret key, and region where all the resources will be deployed.

Now, we will create a key pair by using AWS CLI.

A key pair, consisting of a private key and a public key, is a set of security credentials that you use to prove your identity when connecting to an instance. Amazon EC2 stores the public key, and you store the private key. You use the private key, instead of a password, to securely access your instances. Anyone who possesses your private keys can connect to your instances, so you must store your private keys in a secure place.

Command to create a key pair:

aws ec2 create-key-pair --key-name Task06
Key Pair is created.

Now in this step, we will launch an EC2 instance.

Amazon EC2 provides a wide selection of instance types optimized to fit different use cases. Instance types comprise varying combinations of CPU, memory, storage, and networking capacity and give you the flexibility to choose the appropriate mix of resources for your applications.

Command to launch Ec2 instance:

aws ec2 run-instances \
--image-id ami-081bb417559035fe8 \
--count 1 \
--instance-type t2.micro \
--key-name Task06 \
--security-group-ids sg-029f57d25afb7bd36 \
--subnet-id subnet-e7f7cd8f
Instance Launched

After launching the EC2 instance we will be creating an EBS volume.

An Amazon EBS volume is a durable, block-level storage device that we can attach to our instances.

Command to create EBS Volume:

aws ec2 create-volume  --volume-type gp2  --size 1  --availability-zone ap-south-1a  --tag-specifications 'ResourceType=volume,Tags=[{Key=Name,Value=CLIEBS}]'

This command will create an EBS Volume of Size 1GB in the same region where we have our Instance running. the tag-specifications attribute is used to give a name to our volume.

Now, we will attach the volume to the launched instance.

Command to attach the volume:

aws ec2 attach-volume --volume-id vol-070a75298a7767e56
--instance-id i-055e7a7a41758257b --device /dev/sdf

In this command, we have to give our Instance ID (To which Instance we want to attach with our volume), Volume ID, and device name.

Now, we will launch the S3 bucket and create Cloudfront distribution.

Amazon Simple Storage Service (Amazon S3) is an object storage service that offers industry-leading scalability, data availability, security, and performance. This means customers of all sizes and industries can use it to store and protect any amount of data for a range of use cases, such as data lakes, websites, mobile applications, backup and restore, archive, enterprise applications, IoT devices, and big data analytics. Amazon S3 provides easy-to-use management features so you can organize your data and configure finely-tuned access controls to meet your specific business, organizational, and compliance requirements. Amazon S3 is designed for 99.999999999% (11 9’s) of durability, and stores data for millions of applications for companies all around the world.

Command to create an S3 bucket:

aws s3 mb s3://bucket name 

Here I have also specified the region by using a region tag.

Now, we will upload anything in the S3 bucket. I have uploaded an Image.

Bucket created and Uploaded object in it.

After this, we will create a CloudFront distribution.

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.

To create CloudFront Distribution command is:

aws cloudfront create-distribution --origin-domain-name <bucket_domain_name>
Distribution has been launched.
Description of the Distribution.

After launching and attaching EBS volume to the launched Instance now we will login remotely into the system and will configure the webserver.

After connecting to the EC2 instance we will install httpd first.

To install httpd on our instance we will be using the yum package installer.

yum install httpd

Now, we will create a partition then we will format and mount the EBS volume created in the above step.

Command used to create a partition:

fdisk device namemkfs.ext4 device name

Now, we will mount or volume to the var/www/html folder as all the code of the website resides here only.

To mount command is:

mount device name /var/www/html
Successfully mounted.

Our volume is mounted now we will write an html file in the /var/www/html location.

S3 Domain Name.

Here, I have used <img> tag in html and given the link of the object uploaded in the S3 bucket.

Now, we have to start the httpd service.

To start the httpd service command is:

systemctl start httpd

We can see the output by using the public IP of the Instance and the output image will come from the S3 bucket as we have given the link of the S3 bucket in our html file.

To reduce the latency period we will use CloudFront distribution. We have created CloudFront distribution in the above step we just have to provide the domain name of CloudFront distribution in place of the S3 bucket object link in our html file.

Cloudfront Domain Name

Now, the image in the output is coming through CloudFront distribution.

Final Output.

Thank you for reading this article. Hope this article will be helpful.



Uditanshu pandey

Technical Volunteer at ARTH-The School of Technologies || Cloud Enthusiast || Ansible ||Flutter || Hybrid Multi Cloud || DevOps || Terraform