High Availability Architecture using 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.
Prerequisites:-
aws configure aws --version
Step 1 : CREATE A KEY PAIR
This key will be further used to log into the instance.
aws ec2 create-key-pair --key-name ha_aws > ha_aws.pem
STEP 2 - CREATING A SECURITY GROUP
This sg will act as a firewall for the instance.
aws ec2 create-security-group --group-name ha_aws_sg --description "ha_aws_sg" > ha_aws_sg.txt
STEP 3 - LAUNCHING AN INSTANCE
Using all the above resources now.
aws ec2 run-instances --image-id ami-08e0ca9924195beba --instance-type t2.micro --count 1 --subnet-id subnet-78253910 --security-group-ids sg-01598c0892a138b3b --key-name ha_aws
STEP 4 - CREATING AN EBS VOLUME
Create the EBS volume of 1 GB which will act as an external hard disk for the instance.
aws ec2 create-volume --volume-type gp2 --size 1 --availability-zone ap-south-1a > ha_aws_ebs.txt
STEP 5 - ATTACHING THE EBS VOLUME TO THE INSTANCE
Attaching the above created EBS volume with the instance.
aws ec2 attach-volume --instance-id i-0bc7307965b2dfc7e --volume-id vol-05a4403f05e8cea3b --device /dev/sdf
STEP 6 - CREATING PARTITION OF EBS VOLUME AND MOUNTING
After logging into the instance using the key we created.
fdisk -l
Format the partition
mkfs.ext4 /dev/xvdf
Before mounting , install apache webserver
yum install httpd -y
Now mount the partition to the folder /var/www/html and then check
mount /dev/xvdf /var/www/html df -h lsblk
STEP 7 - CREATING S3 BUCKET AND ADDING IMAGE IN S3 BUCKET
aws s3 mb s3://ha-aws-s3
Now add the image into the s3 bucket
aws s3 cp . s3://ha-aws-s3 --recursive --acl public-read
STEP 8 - CREATING THE CONTENT DELIVERY NETWORK - CDN
aws cloudfront create-distribution --origin-domain-name ha-aws-s3.s3.amazonaws.com
STEP 9 - DEPLOYING WEBAPP USING THE CLOUDFRONT URL
Now replace the previous url with the cloudfront url
So finally, here the data is being extracted from the s3 bucket but with the help of Cloudfront which leads to low latency and more efficiency.
UTS Australia | Chandigarh University | Pianist
4 年Nice work ?? Sujagi Verma