Using AWS-CLI To Create A High Availability CloudFront Distribution

For More Understanding, Refer my previous article Here

So Lets start:->

What is AWS-S3 ?

Object storage built to store and retrieve any amount of data from anywhere. Get started with Amazon S3. Request more information. Amazon Simple Storage Service (Amazon S3) is an object storage service that offers industry-leading scalability, data availability, security, and performance. It is analogous to any public cloud storage like Google Drive etc.

What is CloudFront ?

Amazon CloudFront is a fast content delivery network (CDN) service that securely delivers data, videos, applications, and APIs to customers globally with low latency, high transfer speeds, all within a developer-friendly environment.

Task Description📄

🔰 Create High Availability Architecture with AWS CLI 🔰

🔅The architecture includes-
- 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 S3 bucket.
- Finally place the Cloud Front URL on the webapp code for security and low latency.

Step 1: Create an EC2 instance to configure the Webserver

# aws ec2 run-instances --image-id <AMI-Id> --instance-type t2.micro --count 1 --subnet-id <Subnet-Id> --security-group-ids <Security-Group-Id> --key-name <Key-Name>

Step 2: Create the EBS Volume

# aws ec2 create-volume --volume-type gp2 --size 1 --availability-zone ap-south-1a

Step 3: Attaching the EBS volume to the EC2 Instance

# aws ec2 attach-volume --volume-id <EBS_Volume_ID> --instance-id <EC2_Instance_Id> --device /dev/sdf

Step4: Creating the partition for newly attached EBS volume

For this, First we need to access CLI of Instance

ssh -i "<Key_Name>" ec2-user@<Public_IP>

Now Format the partition created.

Step5: Install Apache Httpd webserver

# yum install httpd -y

Step6: Mount The Partition at Root directory of Httpd (/var/www/html)

# mount /dev/xvdf /var/www/html

Step7: Create a AWS-S3 bucket so store static data on it.

# aws s3api create-bucket --bucket <Name> --region <Region_Code> --create-bucket-configuration LocationConstraint=ap-south-1

Now add items in this bucket.

# aws s3api put-object --bucket slayer227 --key 1.jpg --body "Local-Path-of-Item"

Change the policies of bucket as well as object (For public access)

  1. Bucket accessible publicly
# aws s3api put-bucket-acl --acl public-read --bucket <Bucket-Name>

2. Objects in bucket accessible publicly.

# aws s3api put-object-acl --bucket <Bucket-Name> --key 1.jpg --grant-read uri=

Step8: Create CloudFront Distribution for S3 bucket.

# aws cloudfront create-distribution --origin-domain-name <Bucket-Name> --default-root-object <Object-Name>

Step9: Now configure Httpd web-server and start it.

and, restart the Httpd service if already running.

Here we go…

This static image is stored in CloudFront

You can connect me on Linkedin




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

The Empty Search Result Anti-Pattern

Testing With RSpec

Build A No-Code Medium Publication Clone With Magic Link Using

HostGator Review (2021) ❇️ Speed Test, Live Demo & My Honest Recommendation

2D Web Rendering with Rust

Does Your IT Solution Support Your Line-of-Business Apps No Matter Where They Live?

Difference between Redshift Spectrum and AWS Athena:

Azure Functions with different Azure services

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
Prajwal Patil

Prajwal Patil

More from Medium

Quick and Cost-Efficient Stablecoin Development with XDC Network

Anchor protocol explain in under 2 minutes

Bridge Security: New Tech Means Bridge Hacks Should be Just a Memory