Let’s Create High Availability Architecture with AWS CLI and setting up Content Delivery Network for low latency

Sweta Sardar
5 min readNov 5, 2020

In this article I’m going to show you how to Create High Availability Architecture with AWS CLI.

🔆Task Description:
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 webapp code for security and low latency.

✡️First we have to create a key-pair -

command : aws ec2 create-key-pair — key-name <value> — query KeyMaterial > <value>.pem — output text > <value>.pem

Let’s check on AWS Console :

Key has been created successfully

✡️Create a security group -

command : aws ec2 create-security-group — group-name <value> — description <value>

Let’s check on AWS Console :

Security group has been created successfully

✡️Now we have to set some inbound rules over AWS Firewall -

We will allow port no. 22 and 80 here :

command:

aws ec2 authorize-security-group-ingress — group-id <value> — group-name <value> — port 22— cidr 0.0.0.0/0 — protocol tcp

aws ec2 authorize-security-group-ingress — group-id <value> — group-name <value> — port 80 — cidr 0.0.0.0/0 — protocol tcp

Let’s check on AWS Console :

Firewall has been successfully set over the AWS

✡️Now we have to launch one EC2 Instance to configure the web server -

command : aws ec2 run-instances — image-id <value> — instance-type <value> — count <value> — subnet-id <value> — security-group-ids <value> — key-name <value>

Let’s check on AWS Console :

EC2 instance has been launched successfully

✡️Now create one EBS VOLUME 0f 1 GB -

command : aws ec2 create-volume — volume-type <value> — size <value> — availability-zone <value>

Let’s check on AWS Console :

EBS volume has been created successfully

✡️Now we have to attach this volume in our EC2 Instance -

command : aws ec2 attach-volume — instance-id <value> — volume-id <value> — device <value>

Let’s check on AWS Console :

EBS volume has been attached in the EC2 instance

✡️Now Install the Apache httpd webserver on the top of AWS -

command : yum install httpd

Let’s see software has been installed or not ?

Here we can see that installation has been completed ! !

✡️Now let’s Check how many hard disk we have -

command : fdisk -l

So we have two HARD DISK : 1. /dev/xvda 2. /dev/xvdf

✡️Now let’s create the partition of 1GB volume :

command : fdisk /dev/xvdf

✡️Now we have successfully created our partition :

Partition has been created successfully

✡️Now we have to format that partition :

command : mkfs.ext4 /dev/xvdf1

✡️Now mount the Document Root(/var/www/html) folder :

command : mount /dev/xvdf1 /var/www/html

Now check it is mounted or not by this command : df -h

Document Root(/var/www/html) has been mounted successfully

✡️Start the httpd service -

command : systemctl start httpd

And for check the service status : systemctl status httpd

Showing all status in this picture

✡️Create S3 bucket to store Static objects used in code such as pictures :

command : aws s3api create-bucket — bucket <value> — region <value> — create-bucket-configuration <value>

Let’s check on AWS Console :

Bucket has been created successfully

Let’s put one object such as picture on the S3 Bucket :

Check on the AWS Console :

Object has been uploaded successfully

Now we can use this URL in our WEB PAGE :

So now I’m putting this URL in my Web Page :

And here we can see that by using this URL our Output is showing clearly :

✡️Setting up Content Delivery Network using CloudFront and using the origin domain as S3 bucket.

command : aws cloudfront create-distribution —origin-domain-name <value>

Check on AWS Console :

CloudFront Distribution has been created

Here we can see our new domain name is given :

shown in this picture

Give this Domain name to Web Page :

Let’s run this web page on the top of Web Server :

15.206.72.180/itzMe.html

So Finally we have setting up the Content Delivery Network and place the CloudFront URL in the Web App code for security and low latency. Now our web page become more faster in terms of speed as Image is coming from AWS Cloud.

THANK YOU FOR READING MY ARTICLE 😊 😊

🔹 !! HAPPY LEARNING !! 🔹

🔹 Keep sharing keep learning 🔹

🔹 Thank You 🔹

--

--