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.

So Let’s start!!

AWS Configure on CLI:

aws configure
aws ec2 create-security-group --description "SG for CLI-Task-6" --group-name task-6 --vpc-id vpc-e1a94b8a
aws ec2 create-key-pair --key-name <Key_Name>
aws ec2 run-instances  --image-id ami-0a9d27a9f4f5c0efc  --instance-type t2.micro --count 1 --subnet-id subnet-734d343f  --security-group-ids sg-05460232b7068a79b  --key-name myhadoopos
aws ec2 authorize-security-group-ingress --group-id sg-05460232b7068a79b --protocol "tcp" --port 80 --cidr 0.0.0.0/0
aws ec2 authorize-security-group-ingress --group-id sg-05460232b7068a79b --protocol "tcp" --port 22 --cidr 0.0.0.0/0

A. Webserver configured on EC2 Instance

To configure the webserver we need to do three steps:

yum install httpd -y
vi /var/www/html/index.html
cat /var/www/html/index.html
systemctl start httpd
netstat -tnlp | grep httpd

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

For this first we will create a EBS volume of size 1GiB

aws ec2 create-volume --availability-zone "ap-south-1b" --size 1
aws ec2 attach-volume --volume-id vol-0c86155bc06111295  --instance-id i-06f6ed074433763d9  --device /dev/sdf
fdisk -l
fdisk /dev/xvdf
lsblk
mkfs.ext4 /dev/xvdf1
mount /dev/xvdf1 /var/www/html/
vi /var/www/html/test.html
cat /var/www/html/test.html

C. Static objects used in code such as pictures stored in S3

For this, first we will create a bucket in S3, Use the s3 mb command to make a bucket. Bucket names must be globally unique (unique across all of Amazon S3) and should be DNS compliant.

aws s3 mb s3://my-task6 --region ap-south-1
aws s3 cp C:\Users\PRATYUSH\Desktop\httpd.png  s3://my-task6/  --acl public-read

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

In the CloudFront delivery network, now we have to create distribution in which the origin domain name is the S3 bucket which we created now and the root object is the file (that httpd image).

aws cloudfront create-distribution --origin-domain-name my-task6.s3.amazonaws.com --default-root-object  httpd.png

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

Now instead of the s3 bucket domain we will update the cloudfront domain name in the code which will provide us low latency.

vi /var/www/html/test.html
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
text-align: center;
}
p {
text-align: center;
}
img {
display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
}
</style>
</head>
<body bgcolor="grey">
<h1> Hello !! Task-6 </h1>
<br />
<p> Web Server ---- EBS Volume </p>
<img src="http://d25udx3ichcjnn.cloudfront.net/" weidht=500 height=200 >
<p> Thank You!! This is using the CloudFront URL </p>
</body>
</html>

Thankyou!

ARTH Lerner