High Availability Architecture on AWS CloudFront

Task Description —

🔰 Create High Availability Architecture with AWS CLI 🔰

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.

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.

Step 1: Launching EC2 Instance Using CLI command

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

aws ec2 run-instances — image-id ami-0bcf5425cdc1d8a85 — instance-type t2.micro — count 1 — subnet-id subnet-1b053f73 — tag-specifications ResourceType=”instance”,Tags={Key=”Name”,Value=”AWS-Instance”} — security-group-ids sg-08bc765d20ed076cc — key-name hadoopkey

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

Step 2: Create And Attach EBS Volume to instance

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

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

aws ec2 attach-volume — volume-id vol-0c577fbfe23bfd5fb — instance-id i-00c717988ca64bced — device “xvdb”

We successfully attached our EBS volume to the EC-2 instance.

Step 3 : Now the EBS storage is attached to the EC2 instance, So we need to login via ssh and do further things so that we can deploy web-server on top of it.

We will use putty here for connecting the instance via SSH protocol

Here We have to provide the public IP address of the instance and key of the instance.

Step 4: Now We have to log in as root user in the instance as root have all the access in the OS.

sudo su — root

Step 5: Now we have to install the Apache server on our instance.

yum install httpd -y

Step 6: As we install the Apache Web-server, Now we have to start the Web-server

systemctl start httpd

Step 7: So let’s see our server is started or not

systemctl status httpd

Step 8: Now we have to check how many drives/volumes does the instance is using, With the following command:-

fdisk -l

Step 9: Now you have to do the partition of the volume to use it. But for doing the partition of volume you have to go inside the disk.

fdisk /dev/xvdb

Step 10: Partition is done, now we have to format the volume using the below-mentioned command.

mkfs.ext4 /dev/xvdb1

Step 11: After formatting the volume I am going to mount the new volume to the /var/www/html folder where I am going to save my code.

mount /dev/xvdb1 /var/www/html

Step 12: Now we are creating a bucket to save all the static data of the webpage using the below-mentioned command.

aws s3 mb s3://skabhi-arth

Step 13: To copy all the static data in the S3 bucket.

aws s3 cp “C:\Users\91721\Downloads\my.jpg” s3://skabhi-arth

Step 14: Now our data is uploaded, But we want to upload this data to the edge location for faster rendering for that we used the CloudFront.

aws cloudfront create-distribution — origin-domain-name skabhi-arth.s3.amazomaws.com

Step 15: We can verify using WEBUI that distribution is created or not

Step 16: Now we have to add cloud front link our code.

Step 17: Now our webpage content is faster and anyone from anywhere can use it without any delay

By using cloud front we have improve security of webpages and decrease the latency also.

Thank You!!

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to use Emmet Snippets in VSCode

Relatives and their never ending cycle to know the result.

Just Because It Isn’t Mobile-Friendly Doesn’t Mean It’s Impossible

Writing an X86–64 Assembly Language Program

How to add code highlighting in Medium articles without leaving the editor

Stepping into Activity tests with ActivityScenarios

Ambilms — Best LMS App

CS373 Fall 2021: Thomas Connor Thompson

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Skabhi

Skabhi

More from Medium

Spring 2022 Virtual Evening Seminars

A 360-Degree Guide to Cost of Hiring Remote Node.js Developers

Redis, Kafka or RabbitMQ: Which MicroServices Message Broker To Choose?

Running 💨💨💨 Apache Kafka on Mac 💻