>_ Create High Availability Architecture using AWS CLI by Intregrating Apache Web Server, EBS, S3 & CloudFront >_

Tamim Dalwai
5 min readNov 13, 2020

--

Hello Guys 🙋🏻‍♂️,

In this article we are going to create High Availability Architecture with the help of AWS CLI.

🔅This 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.

🔰 Perquisites:

Walk through this below article of mine to get better understanding of aws cli.

👆 in above mentioned blog I had created EBS volume of 1gb which we will be using in this architecture.

>_Configure webserver on EC2 instance

🔰 commands :

#sudo -su root: To switch user to admin
#yum install httpd : To install apache web server
#rpm -q htttp : To check installed apache version
#systemctl start httpd : To start the web services.
#systemctl status httpd : To check web server status.
Web Server Configuration

So as you can see guys our web server has been successfully configured on our AWS EC2 instance.

>_Document Root (/var/www/html) made persistent by mounting on EBS Block Device

Before mounting to Document root ,First of all we have to partition & format the attached EBS volume.

PARTITION FORMAT MOUNT

Check out above partition video for detailed understanding…

In this step I have made Document Root i.e. /var/www/html (directory where html files are stored ) persistent by mounting it to the external EBS Volume.

>_Static objects used in code such as pictures stored in S3

What is S3?

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

In this step, I have created S3 Bucket named tamim-dalwai by specifying access control as a public.

NOTE : BUCKET NAME MUST BE UNIQUE UNIVERSALLY

🔰 command :

#aws s3api create-bucket --bucket <bucket-name> --region <region-name> --acl public-read --create-bucket-configuration LocationConstraint=<region-name> : To create a S3 bucket with public access control.
Creation of S3 bucket with Public Access

Now i have uploaded one local image file to tamim-dalwai S3 buckert & again with public access.

🔰 command :

# aws s3 cp <local-path-of-file> s3://<s3-bucket-name> --acl public-read : To upload files to S3 bucket with public access

The S3 bucket provides URL for the uploaded files, So we are going to use that URL in our web code for static part of web app.

OBJECT URL

Now after finding object URL, I have created simple home.html file in the document root directory with <img> tag to make use of static object URL from S3 bucket.

So all done!!! Let’s test our simple web app…

home.html

As you can see guys, we stored our static objects in the S3 Bucket & used them for our Web-App. Even though all is working good, the problem comes when there is such use case where we don’t want to wait our clients while loading the static objects of web app.S3 is best choice in case of durability, but it’s not good when it comes to latency,S3 bucket has high latency i.e. it takes more time to load static files.

So we can say conclude that if thing is only durability S3 is always a good choice but in case of latency we have to look for another AWS services.One of the AWS service is Cloud Front which comes with very low latency.

Let’s understand use of cloud front by practically…

>_Setting up Content Delivery Network using CloudFront and using the origin domain as S3 bucket.

What is CloudFront?

Amazon CloudFront is a web service that speeds up distribution of your static and dynamic web content, such as .html, .css, .js, and image files, to your users. CloudFront delivers your content through a worldwide network of data centers called edge locations. When a user requests content that you’re serving with CloudFront, the user is routed to the edge location that provides the lowest latency (time delay), so that content is delivered with the best possible performance. more…

So let’s create CloudFront Distribution using AWS-CLI :

🔰 command :

#aws cloudfront create-distribution --origin-domain-name <domain-name> : To create CF distribution
Creation of CF distribution

>_ Finally place the Cloud Front URL on the web app code for security and low latency.

As like S3 bucket, Cloud Front Distribution also provides url. By puting that url with our static object we can make our static files load with very low latency. I have updated this new url in the home.html <img> tag…

CF URL

Let’s verify with the browser, whether latency has decreased or not…

CF TEST

Whoa !!! As you can see, even after number of page refreshing our static image file is loading very fast that we can’t even guess whether page is reloaded or not 🔥.

So guys our high availability architecture has been successfully configured with integration of EC2+EBS+S3+APACHE-WEB-SERVER+CF. 💻

😃 Thanks for reading ! 😃

✍Keep Learning✍

--

--

No responses yet