Creating High Availability Architecture via AWS Cloudfront using AWS CLI

Creating High Availability Architecture via AWS Cloudfront using AWS CLI


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.



Steps for performing this task:

  1. Launch one EC2 instance having webserver running
  2. Create one EBS volume containing Source Code
  3. Create one S3 bucket having static objects (like images)
  4. Using above service host a globally accessible website via aws cloudfront for best user experience.

Lets start our practical:

Lets launch one AWS EC2 instance using AWS CLI

First , we have log in to our aws account

aws configure

In this we have to specify our ACCESS KEY and SECRET KEY to login into our AWS Account via CLI.See we can also specify our region in which we want to deploy above services as well as output format for AWS.

No alt text provided for this image

Now we are going to launch one EC2 Instance to run WEBSERVER Services on it.

No alt text provided for this image

So, Finally we launched on EC2 instance on ap-south-1a availability zone.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

So, Finally our EC2 instance is launched we can see it come in AWS WEBUI.

Lets configure apache httpd webserver on it and start its services

Connect to our instance via ssh

See we have installed httpd software using yum and started its services on permanent basis even after reboot.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Now we have to start webserver services here

No alt text provided for this image

Now , Lets create our EBS volume of 1 GB to make our source code for our website permanent/persistent.

Remember you should create EBS in same Availability zone where you launched EC2 as EBS VOLUME SERVICE is ZONAL SERVICE.

No alt text provided for this image


No alt text provided for this image

See Finally our EBS volume is created.

Now, Lets attach this new available EBS volume to our EC2 instance.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

See finally status of EBS changed from "available" to "in-use" as we have attached it to EC2 instance.

Lets mount document root /var/www/html to EBS volume to make it persistent:

But for this we have to create Partition in this new volume and format it.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Now, whatever code/content we put inside document root it would be persistent.

Lets create source code for our web page:

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Now Lets create s3 bucket in ap-south-1 and upload this static image there:

No alt text provided for this image
No alt text provided for this image

Lets Put this image into s3 bucket and remove from local storage:

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Lets copy this url and put into webpage code so that our webpage can fetch image from S3 rather than local storage:

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Lets create CloudFront distribution service and specify origin-domain-name as our S3 Storage containing hackerone_image.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Now finally our Cloudfront distribution is created .

Now use this special url given by Cloudfront. This url is internally using Route53 service of AWS to recognize the nearby edge location to fetch this image in our webpage.

Cloudfront also provides lots of monitoring services to know viewers of our webpage.

To view or add a comment, sign in

More articles by Shubham Bhardwaj

Others also viewed

Explore content categories