High Availability Architecture with AWS CLI

Swapnilsukare
7 min readJan 14, 2022

--

TASK 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 web app code for security and low latency.

This is an important article on the Creation of High Availability Architecture with AWS CLI. In this article, I am going to explain how to create a High Availability Architecture with AWS CLI. The architecture should include an Apache webserver running on EC2 and the document root (/var/www/html) should be made persistent by mounting on EBS Block Storage.

Static objects should be placed inside S3 and that object should be publicly accessible.

Content Delivery Network (CDN) should be set up using CloudFront (AWS service) with the domain as an S3 bucket. Finally, we have to put a webpage with CloudFront URL(for ex: http://d1fu7qkqsejp2g.cloudfront.net/) in /var/www/html for security and low latency.

Prerequisites:

🌀AWS CLI installed

🌀We have to add the installation directory to the path environment variable manually.

What really is Cloudfront?

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.

So, here we start with our task:-

For configuration, you require AWS Access Key ID and AWS Secret Access Key.

Step 1: Use aws configure cmd

aws configure

Step 2: If you already have the key use the same key.

command used :

aws ec2 describe-key-pairs

if you don’t have key use the given command :

aws ec2 create-key-pair --key-name <Key>

Step 3: Now create the security group and add an inbound rule

A command for creating a security group is :

aws ec2 create-security-group --group-name "Security_Group_For_ARTH_TASK_6" --description "Security_Group1" --vpc-id vpc-e722398f

A command for creating an inbound rule is: for port 22

aws ec2 authorize-security-group-ingress --group-name "Security_Group_For_ARTH_TASK_6" --protocol "tcp" --port 22 --cidr "0.0.0.0/0"

A command for creating an inbound rule is: for port 80

aws ec2 authorize-security-group-ingress --group-name "Security_Group_For_ARTH_TASK_6" --protocol "tcp" --port 80 --cidr "0.0.0.0/0"

Step 4: Now, Create the AWS instance as we have done other processes like creation of security group, inbound rule, and key-pairs.

aws ec2 run-instances --image-id ami-0a9d27a9f4f5c0efc  --instance-type t2.micro --count 1 --subnet-id subnet-3c161654 --security-group-ids sg-091586fa8140667b1  --key-name docker1

Now we are good to go to configure the Webserver on the ec2 instance. Here I am using putty software to log in remotely.

Note: If your key is in .ppm form convert it into .ppk form, by using puttygen software.

Open the puttygen software, load your key and click on the save as private key option and then choose .ppk format.

Step 5: We need to configure the webserver on the EC2 instance.

For this, we have to install httpd software.

yum install httpd -y

Step6: Now, configure the path

vi /var/www/html/text.html

Step7: Now, start your httpd service

systemctl start httpd

Step8: Now, look for the status of your httpd service whether it is active or not.

systemctl status httpd

Step9: You can see whether the httpd is running or not:

netstat -tnlp | grep httpd

Step10: Now, here you can see the web-server is running.

Step11: Here we are providing with availability zone where this volume needs to be created and finally, it will create a volume.

aws ec2 create-volume --availability-zone "ap-south-1a" --size 15

Step12:Now as the volume is created so we need to attach this volume with the ec2 instance.

aws ec2 attach-volume  --volume-id vol-0b7d2210aa3d11076 --instance-id i-096032997bc4b0c94  --device /dev/sdf

Step15: We can also check in the instance whether it is attached or not

fdisk -l

Step 16: Now we have to make the document root of Apache webserver ( httpd ) permanent so first let’s create one partition in the block storage ( /dev/xvdf ) with ext4 format type and then we will mount it with the document root.

Partition of the attached EBS Volume:

fdisk /dev/xvdf

We can confirm using the command:

lsblk

We can see that one new partition of 15G is created named xvdf1. Now we need to format the partition xvdf1 with the ext4 format type. For that, we can use

“mkfs.ext4 xvdf1” command.

Step 17: Formatting

mkfs.ext4 /dev/xvdf1

Step 18: Mounting

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

After that, we can verify with the “df -h” command.

df -h

Now, search for this page http://<your-ip>:80/text.html

Note: you can use setenforce 0 to disable, when it shows forbidden error it is due to Selinux

Step 19: Now we can create an S3 bucket to put all static objects in it and then we will use it on our web page. So, let’s create an S3 bucket.

aws s3 mb s3://1234bucket --region ap-south-1

So an S3 bucket will be created with the name called 1234bucket. We can verify this from the AWS management console.

Step 20: As a bucket is created so now we can upload the static object. and make publicly accessible.

aws s3 cp C:\Users\Asus\Desktop\pratik11111.jpg  s3://1234bucket/  --acl public-read

URL:

The image inside the Bucket:

Step 21: Now let’s update this URL in the text.html file present in /var/www/html/

The output of the text.html file:

Step 22: Now, we have to create a distribution in the CloudFront delivery network, in which the origin domain name is the S3 bucket.

Step 23: Cloudfront provides us domain name when we put this domain name in the search bar. What output does it give let’s see?

Step 24: Now we can use the Domain Name provided by CloudFront Distribution in our HTML code to provide SDN facility to clients.

Let’s put this CloudFront Distribution domain name in HTML code to access the static object.

text.html code :

<!DOCTYPE html>
<html>
<head>
<title>TITLE</title>
</head>
<body bgcolor="yellow">
<h1 style="font-size:5vw" ><u> <center>Hello Folks!!! This is my Arth Task-6.</center></u></h1>
<center><img src = "http://d1fu7qkqsejp2g.cloudfront.net/" height=550 width=500></center>
<center><b> Task Done Successfully!!!</b> </center>
</body>
</html>

Step 25: Webpage

Conclusion:

CloudFront is a CDN (Content Delivery Network). It retrieves data from the Amazon S3 bucket and distributes it to multiple datacenter locations. It delivers the data through a network of data centers called edge locations. The nearest edge location is routed when the user requests for data, resulting in the lowest latency, low network traffic, fast access to data, etc.

Thanks for reading the article.

#arthbylw #vimaldaga #righteducation #educationredefine #rightmentor #worldrecordholder #ARTH #linuxworld #makingindiafutureready #righteudcation #webserver #cloudfront #aws

--

--

No responses yet