High Availability Structure Using AWS CLI

In this blog, I am going to show you how to create a high availability structure over AWS using CLI.

To launch the ec2 instance we can run the following command:

aws ec2 run-instances — image-id ami-xxxxxxxx — count 1 — instance-type t2.micro — key-name MyKeyPair — security-group-ids sg-903004f8 — subnet-id subnet-6e7f829e

After this, we need to install and configure the webserver

Step 1: Installing httpd server in the cloud using CLI.

yum install httpd -y

This will install the Apache HTTPd web server in our EC2 instance.

Step 2: Starting the httpd services.

systemctl enable httpd --now

This will start the httpd services and the enable option will make the service run time. This means as soon as the instance starts the httpd services will also be started.

Step 3: Creating a new EBS volume.

aws ec2 create-volume --size 1 --availability-zone us-east-1e

This command will create a new volume of size 1Gb in the availability zone us-east.

Step 4: Attaching the EBS volume.

aws ec2 attach-volume --instance-id XXXX --volume-id vol-XXXX --device /dev/sdf

This will attach the created volume to the ec2 instance. Now to use this volume we need to format it.

Step 5: Formatting EBS Volume.

We can format the EBS volume be this command

mkfs.ext4 /dev/xvdf

Here we are formatting it with the ext4 format

Step 6: Creating an S3 bucket and then copying the content.

We can put all the static contents like the pictures, videos in the S3 bucket for better management of our web app.

aws s3api create-bucket --bucket task6arth --region us-east-1e

This command will create an s3 bucket with the name test1 in the us-east-1e region.

Step 7: Creating a CloudFront.

Cloud Front is the service provided by AWS for fast content delivery that securely delivers data, videos, applications, and APIs to customers globally with low latency, high transfer speeds, all within a developer-friendly environment.

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

With the above command, we create a CloudFront service with the endpoint of S3. That means the Cloud front will take the content directly from the S3 bucket

The content provided in the Cloud Front is :

Now, our high availability architecture is created over AWS

Output Screen

That’s all, Thank you for reading this blog.

Hope you find it useful!