High Availability Architecture on AWS CloudFront

Abhishek Mahajan
8 min readNov 11, 2020

Hey Guys !! In the following Article, we will learn what is AWS CloudFront, how we can deploy a Web-server using CloudFront and other AWS services, and how we can achieve a High Availability Architecture. We will achieve all this on the AWS Command Line Interface (CLI) !!!

We will Launch an AWS EC-2 Instance; Create, attach, and configure an AWS EBS Volume to this instance; Create an AWS S3 bucket, Create a CloudFront Distribution and deploy it from the EC-2 Instance.

AWS CloudFront

AWS Cloudfront is one of the leading content delivery network services or CDN ( Content Delivery Network). The CloudFront is a popular service to provide web content management and distribution service with scalable features. It processes and distributes both static and dynamic web content along other files like images, videos etc with low latency and high transfer rates.

AWS CloudFront distributes the content that is sourced from Amazon S3 bucket store through regional centers known as edge locations. Edge locations are physically present all over the Globe, this is how we achieve high speed and low latency. The CloudFront service supports caching for faster web content delivery based on the content available on the CloudFront edge locations. It stores caches of the original data for a limited time. When using CloudFront, one can access data from any edge location. If the data is on the Edge location the User is working on, then CloudFront is achieved; else Cache data is retrieved from the original data to the present edge location

So, let us start setting up our High availability Architecture !!

Firstly, we need to login to our AWS CLI account from our CMD Prompt.

In my previous Article, we learnt basics of AWS CLI, like. We Installed AWS on our Local Computer, launched an EC-2 instance in it, attached an EBS volume to it. As the basics have been covered, I will directly use the commands, but for more descriptive knowledge, check out the previous article on AWS CLI !!

1] Creating an AWS EC-2 Instance

Let's start by creating an AWS EC-2 Instance of ‘Amazon Linux 2 AMI’

aws ec2 run-instances --image-id ami-0947d2ba12ee1ff75 --instance-type t2.micro --count 1 --subnet-id subnet-589fe015 --tag-specifications ResourceType=”instance”,Tags={Key=”Name”,Value=”AWS-Instance”} --security-group-ids sg-bcca5d83 --key-name HadoopNew

We successfully created an Instance. We can verify this from the AWS GUI -

: : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :

2] Creating an AWS EBS Volume

Now, we will create an AWS EBS Volume in the same region.

aws ec2 create-volume --volume-type gp2 --size 1 --availability-zone us-east-1a --tag-specifications ResourceType=volume,Tags={Key=”Name”,Value=”EBS-vol1”}

We successfully created an EBS Volume. We can verify this from AWS GUI -

: : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :

3] Attaching the AWS EBS Volume to EC-2 Instance

aws ec2 attach-volume --volume-id vol-072c3646560ddc5aa --instance-id i-0e50c148d2bc40b2d --device /dev/sdf

We successfully attached our EBS volume to the EC-2 instance. We can see the Volume attached to the EC-2 instance in Attachment Information.

: : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :

4] Installing HTTPD

Now we install httpd server (web-server) on our EC-2 instance. Apache HTTPD is an HTTP server daemon produced by the Apache Foundation. It is a piece of software that listens for network requests (using the Hypertext Transfer Protocol) and responds to them. With httpd, make our own web servers.

So we login to our EC-2 instance by remotely login in using putty.exe or from our CMD Prompt by the following command :

ssh -i HadoopNew.pem ec2-user@34.204.42.206

Now, we install and start httpd service : “yum install httpd” and “systemctl start httpd”. “systemctl enable httpd” to start httpd start permanently.

: : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :

5] Partitioning attached EBS Volume

We are gonna make a partition of the drive that we have mounted and format it because whenever we take a new drive we have to format it. Once it is formatted, we will mount our main folder that is html folder (/var/www/html/) so if incase if OS gets corrupted, data will be saved in that drive and we can launch new OS and .

When we run the command __> “fdisk -l” in our instance, we see all the drives attached to our EC-2 instance.

The /dev/xvdf/ Disk is the EBS Volume we attached. We will create a partition of this Disk.

fdisk /dev/xvdf

Partition Created. We can check from “fdisk -l”. After this, we format it and mount it to the /var/www/html/ Directory/

Format : mkfs.ext4 /dev/xvdf1

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

To check which folder we mounted it to which disk, use __> “df -h”.

We Successfully formatted and mounted the partition. To check this use command __> “df -h”

: : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :

6] Creating an AWS S3 Bucket

Now, for using AWS CloudFront Service, we require an Original S3 bucket where we will have all our Original Data. From this bucket, CloudFront will receive original data and it will create caches for distribution.

aws s3api create-bucket --bucket test-bucket4765 --region us-east-1

We can verify Bucket from Web-UI

> Now, we enter data (files) into the bucket, image for example, so that when we give its path to CLoudFront Distribution, we can view this image

aws s3 cp 11.png s3://test-bucket4765/

We even make this bucket public access so that anyone accessing the bucket can view it :

aws s3api put-object-acl --bucket test-bucket4765 --key 11.png -- acl public-read

## Creating Cloudfront Distribution

Now, after the above steps, we are ready for deploying our AWS CloudFront Distribution. We will create a new CloudFront Distribution which will provide it with the S3 bucket containing the image.

aws cloudfront create-distribution --origin-domain-name test-bucket4765.s3.amazonaws.com --default-root-object 11.png

Now, we created a CloudFront Distribution with its origin domain as the S3 bucket. Here, we are provided with a CloudFront link. This link we need to add in our html file in the httpd main folder (/var/www/html/) so that we can deploy our Website. We go to /var/www/html/directory and add the link in site.html.

Now, we Successfully Launched our AWS CloudFront Distribution. Anyone opening the URL anywhere in the world will be able to view the data in seconds. This is because Cloudfront will intelligently make a local cache of that data, acquiring it from the Origin, in a edge location nearest to the client across the globe, because of which we achieve low latency.

As a result, we are able to use the URL from anywhere in the world -

In this way, we deployed our own web page using the power of AWS CloudFront using only the command line Interface (CLI).

Thank You for reading this blog. Hope you find it useful!!

#awscloud #awscli #aws #vimaldaga #righteducation #educationredefine #rightmentor #worldrecordholder #linuxworld #makingindiafutureready #righeudcation #awsbylw #arthbylw

--

--