Deploying High Availability CDN Architecture on AWS Using AWS CLI

This blog aims to implement the webserver high availability architecture on AWS using AWS CLI. Furthermore, additional EBS storage will be used to make the architecture permanent/highly available, S3 service will be used to store the static objects for the Webserver. Moreover, CloudFront will be used for CDN services.

Harshit Dawar
The Startup
6 min readOct 31, 2020

--

Considering any business, high availability is the core requirement, irrespective of the type of business, if the business has to grow, then it has to be available, otherwise business can not grow if the business products are not available.

Also, in addition to availability, there is one more factor that is “how fast the services of the business can be accessed?”, this factor also plays a very important role in business growth in today’s rapid world.

For example, consider online e-commerce company “Flipkart”, if the site of Flipkart is not available then, then Flipkart can not grow, moreover it will vanish from the e-commerce market in few weeks even because it is not available. Now, coming to the speed of availability of the services of Flipkart, consider a case in which the site of Flipkart takes too much time to load, in this case even, Flipkart’s customers will stop accessing the website because they will be irritated/annoyed with this latency in the website loading.

Therefore, it can be concluded that to have a highly available business architecture in combination with low latency in the service accessibility is very much important. This blog will explain the process of creating the same architecture using a very basic example on top of AWS Cloud.

Architecture to be covered by this blog!

  • Creating an AWS EC2 instance.
  • Configuring the Webserver in the launched EC2 Instance.
  • Making the Webserver documents/content persistent.
  • Creating an object storage S3 bucket for the static content of the website.
  • Storing the static objects related to the business in the object storage S3.
  • Creating a CDN (Content Delivery Network) using AWS CloudFront(to make services available at a low latency across the globe).
  • Integrating Website & the CloudFront URLs.

Note: Complete architecture will be set up using AWS CLI. Also, I am considering that the readers of this blog are comfortable with the AWS basic services.

Creating an AWS EC2 instance!

Run the below-given command to start an EC2 instance on AWS. (Tune the command parameters according to your requirement).

AWS EC2 Instance created & running [Image by Author!]

Note: Launch the instance using either RedHat OS or Amazon OS if you want to use the exact commands shown in this blog, otherwise if you use any other OS, then you have to use the commands supported by that OS to follow along this blog.

Configuring the Webserver in the launched EC2 Instance!

Apache Webserver is used for this practical/project. To configure the webserver, login to the EC2 instance which is created & follow the below-mentioned steps:

  1. Install the Webserver

Run the command highlighted in the image to install the webserver.

Command to install the Webserver [Image by Author!]
Webserver Installation Continued [Image by Author!]
Webserver Installed Successfully [Image by Author!]

2. Running the Webserver services & enabling them to start every time at the time of OS boots up.

Commands to start & enable the webserver services & checking the status of the service [Image by Author!]

Making the Webserver documents/content persistent!

When the above step(installing webserver) is complete, by default the directory “/var/www/html” will be created.

In order to make the files for the webserver persistent i.e. to make the directory “/var/www/html” persistent, additional storage has to be linked/mounted to the directory.

To create the additional EBS storage on AWS, follow the below steps:

  1. Creating an EBS Storage.

Run the below-given command according to your need:

2. Attach the volume to the instance

Run the below-given command:

3. Create partitions in the drive

After the drive is attached to the EC2 instance, partitions have to be created inside that, so that it can store the data.

Create the partitions by “fdisk -l” command or any other preferred way.

4. Format the partitions

Once, the partition is created, it has to be formatted to store the data.

Command to format the drive [Image by Author!]

Note: in the above-given command, write your partition name instead of the above-mentioned one in the image, because there is a high chance that your partition name may vary.

5. Mount the partition to the Webserver Document Root

To mount the partition, run the below-given command:

Creating an object storage S3 bucket for the static content of the website!

To create the S3 bucket for the static content, run the below-mentioned command:

Note: If you are creating the bucket in the ap-south-1 region, then the above command will be changed to:

Storing the static objects related to the business in the object storage S3!

Run the below-given command to upload the objects to the S3 bucket created in the above step:

Creating a CDN using AWS CloudFront!

Run the below command to create a CDN service using AWS Cloudfront:

Integrating Website & the CloudFront URLs!

In your webpage file, add the CloudFront URLs so that can be loaded quickly on the website. For example, a sample code of the webpage displaying an image using CloudFront URL & some text could be like:

Sample PHP code for the webpage [Image by Author!]

The above code has to be created inside the document root of the webserver i.e. “/var/www/html”.

Now, when the webserver service is been requested, the above code will show the output as:

Webserver Output [Image of Author by Author!]

I hope my article explains each and everything related to the topic with all the deep concepts and explanations. Thank you so much for investing your time in reading my blog & boosting your knowledge. If you like my work, then I request you to give an applaud to this blog!

--

--

Harshit Dawar
The Startup

AIOPS Engineer, have a demonstrated history of delivering large and complex projects. 14x Globally Certified. Rare & authentic content publisher.