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 AWS EC2 Instance:

you can create an AWS EC2 instance from GUI or by using the below command:

I am already having an instance named task6 (which is in the stopped state)

EC2 instance — task6 (stopped)

For starting the Instance we need to use the following command:

Now, we can see the task6 instance is running:

running state

STEP 2: Webserver configuration on EC2 Instance

For configuration of web server, we need to install httpd software using command: # yum install httpd and start the httpd service using the command: #systemctl start httpd

yum install httpd
Installation done
running webserver

STEP 3: Create an EBS volume of 1 GB

AWS Command to create EBS volume:

command output:

Now, we can also see in the GUI, volume of 1GB is created:

STEP 4: Attach this EBS volume of 1 GB with EC2 Instance

AWS Command to attach volume:

Command output:

Now, we can see the 1GB of volume is attached:

volume attached

STEP 5: Create a partition, format and mount it to /var/www/html

mount the partition to /var/www/html

Now, we have successfully made Document Root(/var/www/html)
persistent by mounting on EBS Block Device.

STEP 6: Create AWS S3 Bucket

AWS Command to create S3 bucket:

# aws s3api create-bucket — bucket webimages9 — region ap-south-1 — create-bucket-configuration

Now, we can see the S3 bucket is created:

STEP 7: Upload Images to the ‘webimages9' bucket

I have uploaded some more images

STEP 8: Create a CloudFront Distribution

Command to create CloudFront Distribution:

# aws cloudfront create-distribution — origin-domain-name webimages9.s3.amazonaws.com

CloudFront Distribution Created

STEP 9: Create HTML file in instance and provide image URL of CloudFront to this HTML file

index.html created

STEP 10: Check Website Hosted Successfully or Not

if I type I am getting my index.html page output 😃

index.html webpage

But on this website, all the images are coming from AWS CloudFront.

Thank you for reading!! 😇

index.html (which I uploaded at /var/www/html location):



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