Create High Availability Setup On AWS using CLI
Today we are going to create a high availability setup in the AWS cloud using the command-line interface
Let's see the agenda for today
🔅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.
So Let’s start the practical.
As you know we are configuring all the setup using the aws CLI so first you need to setup CLI in your own local machine so that we can directly connect to API
here you will find the AWS CLI software link
And run configure command
aws configure
Here starts the main part of the demo
Step 1: we are going to launch an instance
- select image id
- instance type
- subnet id
- security group
- name of instance
aws ec2 run-instances — image-id ami-0e306788ff2473ccb — instance-type t2.micro — count 1 — subnet-id subnet-cacdb286 — security-group-ids sg-0eea9dcee9f766f35 — key-name “first new instance”
Note: depending on the requirement command will change
Step 2: Lauch the ebs volume
- select instance type
- availability zone
- volume type
- specifications(tags)
aws ec2 create-volume — availability-zone ap-south-1b — volume-type gp2 — size 1 — tag-specifications ‘ResourceType=volume,Tags=[{Key=” “,Value=” ”}]
step 3: Attaching ebs volume to ec2 instance
aws ec2 attach-volume --volume-id <> --instance-id <> --device <>
step 4: Installing apache webserver to instance
so login to your instance
download webserver software and start the service
yum install httpd -y
systemctl start httpd
systemctl enable httpd
step5: Now we have to mount the ebs volume on /var/www/html folder to make the web server highly available to mount the external ebs we have to first create a partition then format it.to perform this use the following commands one by one.
1. fdisk -l #to see the attached volume2. fdisk /dev/sdf #to create partition3. n #to create new partition4. p #to create primary partition5. mkfs.ext4 /dev/xvdf # to format drive6. mount /var/www/html #to mount the ebs
setp6: creating s3 bucket
S3 stands for Simple storage services that provide object storage. We need to create a bucket then we can put our objects like image, video, audio into it and we will get a URL through which we can see our photos, video, or whatever we have uploaded.
- give the bucket a unique name
- region
aws s3api create-bucket - -abhis3bucket2612 - -region ap-south-1- -create-bucket-configuration LocationConstraint=ap-south-1
STEP 10:creating cloud-front distribution
CloudFront is a content delivery network, which basically creates the cache on the edge locations so low the latency. For example, we have an ec2 instance in Mumbai and our customers are from the US so CloudFront will make the cache in the customer’s nearest edge locations so the customer packet will not have to travel more which will low the latency.
aws cloudfront create-distribution - -origin-domain-name abhis3buket2612.s3.amazonaws.com- -default-root-object abhi.jpg
FINAL STEP: NOW WE HAVE TO CLONE OUR CODE IN /VAR/WWW/HTML FILE AND GIVE CLOUD FRONT LINK INSIDE THE CODE.
Thank you, 🙌
see soon in another one 💯
You can connect me on LinkedIn.