Let’s Create High Availability AWS Architecture
Arth Task 6 given by Mr. Vimal Daga Sir
Today we are going to see, how using few AWS CLI commands can make our High Availability AWS Architecture
◼ High Availability means systems that are dependable enough to operate continuously without failing.
◼ And using command-line interface makes it faster and more efficient than scrolling across GUI tabs and dialogs
🟦 What are we going to do ??
- Configure Webserver on EC2 Instance
- Make Document Root(/var/www/html) persistent by mounting on EBS Block Device.
- Make Static objects used in code such as pictures store 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.
🔴 Pre-requisite
✔ Account in AWS
✔ AWS CLI configured
✔ Create a user and login through and CLI
NOTE : If you are not familiar with the CLI commands you can check out this article or visit AWS official site.
🏃♀️🙂 Let’s proceed..
👀 Let’s look deep into… What are we going to do ??
⚠ 💥 All the commands will run in CLI Mode
👉 First and foremost Launch an EC2 instance
👉 To get inside the instance connect via ssh to configure webserver in EC2
👉 Create an EBS volume of 1 GB and attach it to the running instance
👉 Now, In EBS create partition, format it and mount to the Document root (/var/www/html)
👉 Create S3 Bucket and store all the static content in it
👉 And finally create cloudfront and enjoy low latency, high transfer speeds
1️⃣ Configure Webserver on EC2 Instance
To launch an instance we will use the following command
Command : aws ec2 run-instances --image-id ami-0e306788ff2473ccb --count 1 --instance-type t2.micro --key-name thekey1 --security-group-ids sg-09543292eedcf2d26 --subnet-id subnet-06ccd1feb2cb359
2️⃣ To get inside the instance connect via SSH to configure webserver in EC2
Now, we need to go inside the instance for that we need the Public IP which is required to login via SSH
Without using the GUI we can find the public IP through aws ec2 describe-instances
command
Command : ssh <Public_IP> -l ec2-user -i <key_name>.pem
📝Steps to configure Apache Webserver
1. yum install httpd
(Before installing don’t forget to switch to root user)
2. systemctl start httpd`
and start the services
3️⃣ Create an EBS volume of 1 GB and attach it to the running instance
- To create an EBS Volume
Command : aws ec2 create-volume --availability-zone ap-south-1a --volume-type gp2 --size 1
- To attach the volume
Command : aws ec2 attach-volume --device /dev/xvdb --instance-id i-083964f76f7580d55 --volume-id vol-0061c5244faebb2ac
4️⃣ Now, In EBS create partition, format it and mount to the Document root (/var/www/html)
- Command to list all the disk
fdisk -l
Here, we can see /dev/xvdb
is the available disk. Let’s create partition in it using command fdisk <disk_path>
Now if we again, check list of disk using fdisk -l
, We can see a new device appears
2. Before we start using this device it needs to be formatted using command mkfs.ext4 <device_path>
3. The device is ready to use, Let’s mount it the desired folder whose data you want to make persistent/permanent
For more detailed explanation of the partition concept you can refer to World Record Holder’s free class (Its my source of learning too)
5️⃣ Create S3 Bucket and store all the static content in it
S3 Stands for Simple Storage Service (Amazon S3).It is an object storage service that offers industry-leading scalability, data availability, security, and performance. Object storage built to store and retrieve any amount of data from anywhere.
- Creating a S3 bucket in us-west-1 (US West (N. California))
Command : aws s3 mb s3://<bucket_name> --region <region_name>
2. Uploading the static content of the website to the s3 to make it accessible from anywhere.
Command : aws s3 cp <file_name_to_be_uploaded> s3://<bucket_name>/<Name_by_which_u_want_to_save_the_file>.<extension> --acl public-read
To verify if the files uploaded successfully
In browser type <bucket_name>.s3.amazonaws.com/files_name.extension
and see if the image appears
6️⃣ Create cloudfront and enjoy low latency, high transfer speed
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.
It is based on the concept of Content Delivery Network (CDN), when using CDN client faces latency only in first go, after that data gets copied in nearest data center(edge location)
◼ Command to create cloudfront
Command : aws cloudfront create-distribution --origin-domain-name <bucket_name>.s3.amazonaws.com
This will give you a domain name which will be used as universal link for all the files in the s3 bucket
Use the Cloudfront domain name to access the files
In browser type <Cloudfront_domain_name>\file_name.extension
🤩 Setup is done !!!!
In your code wherever you want to use the images, instead of the local file address use this url with cloudfront domain name.
🙂 Hope it will help you setup and launch website with low latency and high transfer speed. for any doubts or suggestions, you can ping me on Linkedin I’ll be happy to help.