How to create High Availability Architecture with AWS CLI and how to Configure Web Server, EBS, S3 & CloudFront & their Integration on AWS

Our aim is to create high availability architecture with aws-cli. For meeting to our aim let’s see how cloudfront service of aws will help us .

Amazon CLOUDFRONT and S3 are two different services provided by Amazon Web Services.

Amazon CloudFront is a middle-ware which stands in between a user requesting for a file from AWS and the S3 data center in a specific region, CloudFront is used to speeds up distribution of your static and dynamic web content from S3 to the User.

✔ Prerequisites :

Before configuring webserver on EC2 instances we should know how to launch on AWS , how to use EBS service and some other prerequisites are there I have already created blog for these prerequisites for detailed procedure and understanding go through the link given below. 👇

👆 in above mentioned blog I have created EBS volume of 1gb for demo purpose but for performing current task I have created EBS volume of 2gb

Optional part it is for more understanding how we can use easily aws-cli with automation.

Above same task we can also do by automation. For this how my voice assistant (made by written program in python ) for clarification watch video through following link 👇

After completing with above prerequisites . Let’s move to do further procedure of task with AWS CLI only

  • Created EBS volume of 2GB

We can verify from console of aws also .👇

  • Attached that volume to launched instance through cli

we can verify through aws console.👇

✔ How to configure webserver on EC2 instances

steps to configure webserver which are as follows

  1. Install httpd software using yum

command : yum install httpd

when it ask for yes or no to continue installation we have to press y

after complete installation we can see complete as as last line

  • we can check httpd is installed or not by using following command 👇

command : rpm -q httpd

2. start the installed webserver in my case it is httpd

command start httpd 👉 systemctl start httpd

  • we can check status of httpd

command to check status : systemctl status httpd

in my case it is showing active .

now webserver has configured !

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

Before mounting on EBS block device i created partition inside hard disk i.e externally attached ebs volume of 2gb

1.Let’s see available hard disks by using following command

command : fdisk -l

In below picture, we can see /dev/xvdf is the new EBS volume of size 2GiB is attached.

2. Create one partition of 1GB inside the hard disk i.e externally attached EBS volume of 2GB.

2. To Format

To format the HDD /dev/xvdf1

3.Mount this partition with the the folder /var/www/html/ (Document Root).

✔ How to use static object such as picture in code stored in S3 ?

To do this first we have to create one bucket in S3

. Created bucket named my-task using following command on aws-cli

#aws s3api create-bucket — bucket my-task — region ap-south-1 — acl public read — create-bucket-configuration LocationConstraint=ap-south-1

we can see created bucket in aws console also

Now i have to upload image as a static data in created bucket

I have uploaded image on bucket by using following command

#aws s3 cp local path s3://bucket-name — acl public-read

we can verify that image has uploaded on bucket named my-task

we can see in above picture aws.png file has uploaded

As well as I have made this image as public so that anyone can see and access this image from browser

Let’s see url created by s3 for uploaded image.

  • Now let’s write code of html for displaying that image on webbrowser with some content

in my case I have created file arth1.html inside folder /var/www/html

Now we can see from browser using url : (public ip of instance /filename.html)

in my case it is 13.233.215.76/arth1.html

Image displayed with low speed and highlatency

but this page and image displayed with high latency

we have to meet the condition called low latency for high availability architecture

Let’s see how we will do by using concept of cloudfront to meet the condition of low latency

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

How to Create CloudFront Distribution & Integrate with S3 & Web Server ?

CloudFront : A web service of amazon that speeds up distribution of your static & dynamic web content such as .html, .css, .js , image files etc. to your users.

  • CREATE DISTRIBUTION USING CLI

command : aws cloudfront create-distribution — origin-domain-name my-task.s3.amazonaws.com

we can see created distribution from aws console too 👇

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

when we create distribution on Cloudfront it will create new url .We have to put that url in our html file as url for image source.

Url contains the domain name.so to get make url to put inside code of html in the place of where we have already given the url provided by s3 we have to copy domain name and have to put url as shown below

https://domain_name/image_name(extension)

Now client can easily access the services from the server by using server public IP with very low latency & high speed.

how it will work with low latency you can watch through picture.👇

Image displayed with high speed and low latency

Finally High Availability Architecture has created ……!

Thanks for reading … !☺

Happy Learning….. ☺ ✍

--

--

--

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

Recommended from Medium

Align Visual in Power BI #Shorts #PowerBIShorts #taik18

CONSTRUCTOR IN JAVA….

Plug Talk — 8/12

Software development in the 2020s

Why Is a Good Ping a Good Thing?

Symbolism in NM

Oasis Info byte Internship Experience

Empower your website with pyScript

Priyanka Hajare

Priyanka Hajare

More from Medium

Introducing PoolinWallet Automatic Investment Plan (AIP) Tool “HODL Plan”

20 YouTube Channels For Learning Flutter

MySQL vs PostgreSQL

Create and Launch your own Decentralized Exchange — Uniswap Clone App

Create and Launch your own Decentralized Exchange — Uniswap Clone App