High Available Architecture with S3 and CloudFront using AWS CLI
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.
🤔 Lets think of a situation where we are sitting in Delhi and we wants to access the data from an S3 bucket that is in Australia region or within their availability zone, then there will be a delay in accessing the content which is also termed as Latency Issue!!
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
The main use of CloudFront is to create a local cache and when a client from the nearest location try to access the content, then it will be used by it from the nearest edge location.
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.
In this article, our plan is to create a high availability architecture such that 🔅 The architecture includes-
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.
So lets start the implementation with step by step approach !!!
Step 1 : Configure the aws account within cli, using command “aws configure”
Here we are configuring aws with our own Account credentials.
Step 2 : Create an EC2 instance to configure the webserver on it
It is good practice to add some tags , so that it will be easier to filter !!
Lets check on the dashboard that it has been created or not??
Step 3 : Create and attach the EBS Volume to the EC2 instance
Creating a EBS volume :
Attaching the EBS volume to the EC2 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.
To configure web-server, we need to install httpd using command “yum install httpd -y ”:
Now to use this service, we need to start the service lets check that it is running or not !!
☹️ Ohh..oo !! its not active. So to active this, we use the command “systemctl start httpd”
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.
Create the partition !!
check that the partition has been created or not ?
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)!!
Lets check the blocks, that it has been mounted or not ?
Step 6 : Create S3 bucket to store some static content
Lets check the same on the dashboard
Step 7 : Create a Cloud Front distribution in order to provide CDN
Lets check the same over the dashboard, initially it will be in progress but within some minutes it will be in the deployed state.
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 !!
In my case, IP : 22.214.171.124
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 !!!😇😇