Creation Of High Availability Architecture with AWS-CLI >-

Gulsha Chawla
7 min readAug 24, 2021

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

🤔Let us first understand few concepts related to this task :

What is a Web-Server?💡

✍🏻A web server is a computer that runs websites. It’s a computer program that distributes web pages as they are requisitioned. The basic objective of the web server is to store, process and deliver web pages to the users. This intercommunication is done using Hypertext Transfer Protocol (HTTP). These web pages are mostly static content that includes HTML documents, images, style sheets, test etc. Apart from HTTP, a web server also supports SMTP (Simple Mail transfer Protocol) and FTP (File Transfer Protocol) protocol for emailing and for file transfer and storage.

What is EBS?💡

✍🏻Amazon Elastic Block Store (EBS) is an easy-to-use, high-performance block storage service designed for use with Amazon Elastic Compute Cloud (EC2) for both throughput and transaction-intensive workloads at any scale.

✍🏻For eg: Pendrive

What are static objects?💡

✍🏻Static based objects are also called automatic objects or local objects.

✍🏻Static objects are created each time it’s declaration is encountered in the execution of program.

✍🏻Static objects are allocated storage in static storage area for eg : EBS or S3 bucket.

What is S3 bucket? Why we use it ?

✍🏻Amazon Simple Storage Service (Amazon S3) is an object storage service that offers industry-leading scalability, data availability, security, and performance

✍🏻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.

What is Cloud Front ? How it uses Content Delivery Network?

✍🏻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.

✍🏻CloudFront is integrated with AWS — both physical locations that are directly connected to the AWS global infrastructure, as well as other AWS services.

Basic Architecture

Now let’s jump to the practical part👇🏻

Step 1: Webserver configured on EC2 Instance

Here initially we will do some steps of task 3 also

Firstly will create a new key pair using this command :

#aws ec2 create-key-pair — key-name myawskey

You can verify through Web-UI also

Now let’s launch one instance using this command :

#aws ec2 run-instances — image-id ami-0938d9558bf1b4533 — count 1 — instance-type t2.micro — key-name myawskey — security-group-ids sg-03ee4f414274ca22f — subnet-id subnet-a9959dc1

We can also verify this using our Web-UI

So let’s now configure this instance as webserver

Prerequisites : For configuring the webserver on Ec2 instance we have to install httpd software which is a product of Apache.

Following are the commands to install a webserver :

#yum install httpd: it will install httpd software for us.

#systemctl start httpd: this will start services of apache web server

#systemctl status httpd: to check services of web-server active or inactive.

#systemctl enable httpd: to permanently enable status of services.

Step 2 : Document Root(/var/www/html) made persistent by mounting on EBS Block Device.

Here firstly we will create an EBS volume using this command :

#aws ec2 create-volume — volume-type gp2 — size 3 — availability-zone ap-south-1a

We can verify using web-UI that EBS is now available i.e created.

Now we will attach this EBS volume to our instance using this command :

#aws ec2 attach-volume — volume-id vol-06d993c3ca268f61f — instance-id i-0c368387a3153e75c — device /dev/sdf

As in web-UI, we can see it’s now attached i.e in-use

Now we have to do Partitioning, format, and mount our attached EBS volume.

Hereby using #fdisk -l we can verify EBS volume is attached or not

As we are first time creating partitions use #fdisk /dev/xvdf then press p i.e primary partition and press n to create a new partition than to save it press w.

To Format this volume use #mkfs.ext4 /dev/xvdf1

To connect our new hard disk to O.S or instance we always need a driver because the driver is the one who manages kernel systems. So for driver, we use #udevadm settle

To Mount this volume to Document Root Folder i.e /var/www/html we use #mount /dev/xvdf1 /var/www/html

We can also verify it by using # df -h command.

Now We have to go to /var/www/html/ directory to configure or store our HTML code for webapp using cd /var/www/html/

#vi gc.html : To create a html webpage.

Step 3: Static objects used in code such as pictures stored in S3

Now we have To store Our Static Data(Like videos, pictures, pdf, etc) on S3 so we have to first create our S3 Bucket and Upload the File To that so that we can use the link of S3 in our Webapp to deliver our contents.

So we will create an S3 bucket using this command and also providing public access so that anybody can access it.

#aws s3api create-bucket — bucket gc2608 — region ap-south-1 — acl public read — create-bucket-configuration LocationConstraint=ap-south-1

We can also verify from Web-UI

To upload any file to the S3 bucket use this command:

#aws s3 cp local path s3://bucket-name — acl public-read

We can verify it is uploaded by Web-UI

Hence, we have successfully saved our static data to the S3 bucket. Now we will use the link of our file to add in our HTML code.

Let’s run our web page Instance-IP/gc.html.

But this is not a High Availability Architecture because this architecture doesn’t satisfy the following conditions:

  1. Low Latency
  2. Don’t Use the AWS Global Infrastructure

So in order to meet the Low latency and use the high-speed data transfer, we must use the Content delivery network (CDN) concept.

Step 4: Setting up Content Delivery Network using CloudFront and using the origin domain as S3 bucket.

Firstly we will set up Content Delivery Network using CloudFront in Amazon-CLI by this command :

# aws cloudfront create-distribution — origin-domain-name gc2608.s3.amazonaws.com

Creating Cloud-Front Distribution

Step 5: At last, place the Cloud Front URL on the web app code for security and low latency.

URL of cloud front

Finally, our WebApp is created with High Availability Architecture 🥳🥳🥳

Thank you for reading my article🤗

Keep Learning🤩Keep Sharing🤝

Good Day😊

--

--