High Availability Architecture with AWS CLI
This new task revolves around AWS CLI and its power. Here, we are going to create a High Availability Architecture with AWS CLI .
The steps to achieve this architecture are as follows -
- 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.
Let’s jump into the execution.
Step 1: Configure Apache Webserver on a EC2 instance.
Sub Steps involve : creating a new EC2 instance, setting up keys, security groups and launching the instance
(for completing the sub-steps refer → https://niharicka.medium.com/key-pair-security-group-volume-creation-on-aws-using-cli-c7e28d3eceab)
For installing Apache Webserver on AWS, use the following command (here I’m using a RHEL8 instance)
[root@ip-172-16-97-255 ~]# yum install httpd -y
# here "y" argument is used for "yes" permission for installing/
# downloading the software package.
[root@ip-172-16-97-255 ~]# systemctl enable httpd --now
# enable the service
Step 2: Document Root(/var/www/html) made persistent by mounting on EBS Block Device.
Sub Steps involve : creating a new EBS volume, attach this EBS volume to the existing instance using CLI.
# CREATION OF EBS VOLUME
[root@ip-172-16-97-255 ~]# aws ec2 create-volume --availability-zone ap-south-2a --volume-type gp2 --size 1
# ATTACH THE EBS VOLUME TO THE EXISTING EC2 INSTANCE
[root@ip-172-16-97-255 ~]# aws ec2 attach-volume --instance-id-2a65bjhwt577h3ce3 --volume-id vol-yte7364dfghj --device /dev/sdb
# CHECK WHETHER THE ATTACHING WAS SUCCESSFUL
[root@ip-172-16-97-255 ~]# fdisk -l/* here you will see a list of partitions present along with their description, make sure you use root powers to access the same*/
# CREATING FILESYSTEM FOR THE NEW EBS VOLUME
[root@ip-172-16-97-255 ~]# mkfs.ext4 /dev/xvdb
# MOUNTING EBS VOLUME TO THE DOCUMENT ROOT
[root@ip-172-16-97-255 ~]# mount /dev/xvdb /var/www/html/* here the "var/www/html" is the default location of the apache webserver */
Step 3: Static objects used in code such as pictures stored in S3
Sub Steps involve: creating a S3 bucket, uploading a picture in the bucket, giving public accessibility to the object.
# CREATION OF S3 BUCKET
[root@ip-172-16-97-255 ~]# aws s3api create-bucket --bucket cloudfrontt6 --region ap-south-2a --create-bucket-configuration LocationConstraint=ap-south-2a
# UPLOAD IMAGE INTO THE S3 BUCKET
[root@ip-172-16-97-255 ~]# aws cp X:/HSD/bg.png s3://cloudfrontt6 upload: .\bg.png to s3://cloudfrontt6/bg.png
# ENABLE PUBLIC ACCESSIBILITY
[root@ip-172-16-97-255 ~]# aws s3api put-bucket-acl --bucket cloudfrontt6 --grant-read uri=http://acs.amazon.com/groups/global/AllUsers[root@ip-172-16-97-255 ~]# aws s3api put-bucket-acl --bucket cloudfrontt6 --acl public-read-write[root@ip-172-16-97-255 ~]# aws s3api put-object-acl --key bg.png
--bucket cloudfrontt6 --acl public-read-write/* Now with the help of Object URL, one can access the data of the S3 bucket */
Step 4: Set-up Content Delivery Network using CloudFront service and using the origin domain as S3 bucket.
Sub Steps involve: create cloudfront distribution using s3 bucket
# CREATION OF CLOUDFRONT DISTRIBUTION USING DOMAIN NAME AS S3 BUCKET
[root@ip-172-16-97-255 ~]# aws cloudfront create-distribution
--origin-domain-name cloudfrontt6.s3.amazonaws.com
# UPLOAD IMAGE INTO THE S3 BUCKET
[root@ip-172-16-97-255 ~]# aws cp X:/HSD/bg.png s3://cloudfrontt6 upload: .\bg.png to s3://cloudfrontt6/bg.png
Step 5: Finally place the Cloud Front URL on the Web Application code for security and low latency.
Sub Steps involve: create a webpage, inside the webpage code provide Cloudfront Distribution URL
# CREATION OF WEB PAGE
[root@ip-172-16-97-255 ~]# vi /var/www/html/index.html/* inside the file, mention the following */ < img src="https://gae56fdvasd56aewy.cloudfront.net/bg.PNG" width=1400 height=900 >
Now, to access the web page, go to your browser and type the public IP of the EC2 instance. The web page will be loaded with security and low latency.
THANK YOU!