Creating High Availability Architecture With AWS CLI
Prerequisites:-
- Created an AWS account.
- Install AWS CLI in OS.
- Configure AWS CLI with your IAM user credentials.
What Is AWS CLI?
The AWS Command Line Interface (CLI) is a unified tool to manage your AWS services. With just one tool to download and configure, you can control multiple AWS services from the command line and automate them through scripts.
What is AWS S3?
Amazon Simple Storage Service is storage for the Internet. It is designed to make web-scale computing easier for developers. Amazon S3 has a simple web services interface that you can use to store and retrieve any amount of data, at any time, from anywhere on the web. It gives any developer access to the same highly scalable, reliable, fast, inexpensive data storage infrastructure that Amazon uses to run its own global network of web sites. The service aims to maximize the benefits of scale and to pass those benefits on to developers.
What is AWS Cloud Front Service?
Amazon CloudFront is a web service that speeds up the distribution of your static and dynamic web content, such as .html, .css, .js, and image files, to your users. CloudFront delivers your content through a worldwide network of data centers called edge locations. When a user requests content that you’re serving with CloudFront, the user is routed to the edge location that provides the lowest latency (time delay), so that content is delivered with the best possible performance.
What Is High Availability?
Highly available systems are reliable in the sense that they continue operating even when critical components fail. They are also resilient, meaning that they are able to simply handle failure without service disruption or data loss, and seamlessly recover from such failure.
High availability is commonly measured as a percentage of uptime. The number of “nines” is commonly used to indicate the degree of high availability. For example, “four nines” is indicative of a system that is up 99.99% of the time, meaning it is down for only 52.6 minutes during an entire year.
🔅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 web app code for security and low latency.
Launch a EC2 Instance
First, we have to launch a new EC2 instance in which we will configure our Web Server
aws ec2 run-instances — image-id ami_ — instance-type _type_id — count no_of_instance — security-group-ids group_id — key-name key_name
Confirmation in WebUI :
Now we will Create a New EBS Volume:
aws ec2 create-volume — volume-type volume type — size 1 — availability-zone Zone
Confirmation in WebUI:
Attach EBS Volume to EC2 Instance :
aws ec2 attach-volume — volume-id volume_id — instance-id instance_id — device device_name
After attaching our Volume in the EC2 Instance now lets’s install Apache Httpd in our Instance and then do partition of the volume. After doing the partition we have to mount the partition to /var/www/html folder.
First, we need to install httpd software using the following command:
yum install httpd
Doing Partition and Mounting it to /var/www/html
fdisk -l
fdisk /dev/xvdf
After this just press enter and enter after this enter w.
mkfs.etx4 /dev/xvdf (command used for formatting the partition)
mount /dev/xvdf1 /var/www/html (mounting our partition)
Creating S3 Bucket
We have to create S3 bucket for saving the Static Data of our website in it.
aws s3api create-bucket — bucket bucketname — region ap-south-1 — create-bucket-configuration LocationConstraint=ap-south-1
(bucket name should be unique)
Now upload all your static data in this bucket
Give you S3 bucket and the data uploaded in it permission for public access.
CloudFront Distribution for our S3 Bucket
aws cloudfront create-distribution — origin-domain-name {domain_name}
In the WebUI, you will see a Cloud Front Distribution will get deployed (it takes 4–5 minutes for deploying ). Click on your distribution and copy the Domain Name
Your Cloud Front is now setup. Now go back to your EC2 Instance and add the HTML file in /var/www/html folder and start our web server
1. cd /var/www/html/
2. vi aws.html
Write the HTML code in this file and add the link of your Static Data from the Cloud Front. Save this file.
3. systemctl start httpd
4.systemctl status httpd (to check the status of your webserver)
Your High Availability Architecture is now ready to use
Let’s see the Website which we hosted on our web server