High Available Architecture with S3 and CloudFront using AWS CLI

Using CloudFront with S3

There are a lot of services provided by AWS for different different purposes !! one of them is S3 which provide Storage as a service and lie in the category of object storage. Also, it is a Global service.

Problem Statement

In this article, we will work to resolve this issue of latency using a great service of AWS named CloudFront that provide the service of Content Delivery Network (CDN).

Concept of CDN

Edge locations are refers to the small-small data centers available at multiple locations and internally connected through some physical connectivity . They are not meant for actual storage, they only supposed to have cache data with a default TTL (Time to Live) time of 24 hrs.

CloudFront provide CDN(Content delivery Network) and this service is backed with Edge location that is using Global Network setup by Amazon.

Global Network of Amazon

Our Plan

1. Webserver configured on EC2 Instance

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

3. Static objects used in code such as pictures stored in S3

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

5. Finally place the Cloud Front URL on the webapp code for security and low latency.

So lets move to the Implementation part.

Implementation

Step 1 : Configure the aws account within cli, using command “aws configure

Here we are configuring aws with our own Account credentials.

AWS Configuring

Step 2 : Create an EC2 instance to configure the webserver on it

Creating ec2 instance
Created Instance ID
Successfully created instance

It is good practice to add some tags , so that it will be easier to filter !!

Successfully added tags

Lets check on the dashboard that it has been created or not??

Instance on Dashboard

Step 3 : Create and attach the EBS Volume to the EC2 instance

Creating a EBS volume :

Successfully created the volume

Attaching the EBS volume to the EC2 Instance :

Successfully attached the volume to the instance

Step 4 : Configure the Web Server in the instance

Here i am using Putty program to connect to the EC2 instance in order to configure it for web server setup.

Connected to the EC2 Instance

To configure web-server, we need to install httpd using command “yum install httpd -y ”:

installing the httpd
Successfully Installed httpd

Now to use this service, we need to start the service lets check that it is running or not !!

Not active service

☹️ Ohh..oo !! its not active. So to active this, we use the command “systemctl start httpd

Successfully started the service

You can check the same with the status command used above.

Step 5 : Attaching the external EBS Volume to the web-server document root i.e., /var/www/html

I am not going to use the complete storage of this volume, i will create a partition of 5GB and will only mount it the document root.

Firstly, check the available devices.

Available blocks

Create the partition !!

Created a partition of 5 GiB

check that the partition has been created or not ?

partition available

Before mounting it to the instance, we need to set the driver for the same, then need to format it (that are mandatory to be executed)!!

Successfully formatted and mounted

Lets check the blocks, that it has been mounted or not ?

EBS Volume mounted

Step 6 : Create S3 bucket to store some static content

Successfully created s3 bucket

Lets check the same on the dashboard

Successfully Created S3 bucket
Objects available in S3 bucket

Step 7 : Create a Cloud Front distribution in order to provide CDN

Created CloudFront

Lets check the same over the dashboard, initially it will be in progress but within some minutes it will be in the deployed state.

Deployed Cloudfront Distribution

After successful deployment, we got a Domain Name through this Domain Name we can access any content from the configured S3 bucket at any Geographical location, the wow factor is that 🤩🤩 without any latency.

Step 7 : Create a web page, and access it from the webserver that we have created !!

Final Web page

In my case, IP : 65.0.134.237

Use your instance public IP to perform the same. After he experiment is done, its a good practice to terminate everything !! if it is not in use !!!

I hope you like the Blog and find it useful !!! Any queries and suggestions are highly accepted🤗🤗

💫Keep sharing, keep learning💫

Thank You !!!😇😇

I am a tech enthusiast, researcher and work for integrations. I love to explore and learn about the new technologies and their right concepts from its core.