Creating a High Availability Architecture CloudFront using AWS CLI

Samkit Shah
3 min readOct 27, 2020

We can easily use S3 for object storage as it is designed for large-capacity, low-cost file storage but only in one specific geographical region whereas CloudFront uses the concept of CDN (Content Delivery Network) which creates a cache of the original data at the nearest edge location as close to the user as possible. No matter where ever you are located in the world the data will always be fetched from the nearest edge location to the user which results in low latency.

Here’s what we are going to do We are going to create an architecture that has :

  • Webserver configured on EC2 Instance
  • Document Root(/var/www/html) made persistent by mounting on EBS Block Device.
  • Static objects used in code such as pictures stored in S3
  • Setting up Content Delivery Network using CloudFront and using the origin domain as an S3 bucket.
  • Finally, place the Cloud Front URL on the web app code for security and low latency.

First, we are going to launch an ec2 instance, just in case if you don know how to launch an instance using AWS CLI, you can click here to check how to do it.

Now after we have launched and attached an additional volume to the instance.

Now we have to create a partition of the volume which we attached and for that first, we format the volume, creates a partition, and then mount it to a folder.

mkfs.ext4 /dev/xvdf  #Format the volume
fdisk /dev/xvdf #To create a partition   (p,n,Enter,Enter,Enter)

Now we mount the folder

mount /dev/xvfd /var/www/html

We create an s3 bucket

aws s3api  create-bucket  --bucket samkitbucket  --region ap-south-1   --create-bucket-configuration LocationConstraint=ap-south-1

Now we are going to create a cloud front

aws cloudfront create-distribution  --origin-domain-name  cloudfrontsamkitbucket.s3.amazonaws.com

Now in our HTML code, we are going to provide CloudFront URL instead of S3 to that our architecture would not be limited to only one specific region.

Finally!

--

--

Samkit Shah
Samkit Shah

Written by Samkit Shah

Machine Learning | Deep Learning | DevOps | MLOps | Cloud Computing | BigData

No responses yet