High Availability Architecture with AWS CLI
This is the task given in ARTH(School of technologies) training under Vimal Daga sir.
Task Description📄
🔰 Create High Availability Architecture with 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.
. Explanation
In the following article I have told how to use CLI and shown you by running different services through CLI
Now before doing further things, i created some more power shell variables for future reference.
$image_path = "D:/arth_task6/vishal.jpg" $key_location = "D:/arth_task6/vish_task6_key.pem" $PublicInstanceIP = aws ec2 describe-instances | jq ".Requirements[2].Instances[].PublicIpAddress" Using this I am fetching public of the instance and storing in a variable PublicInstanceIP so that i can login.
->By following command i am installing httpd apache software. This command goes inside the instance login, install software and come out automatically
ssh -i $Key_location ec2-user@$PublicInstanceIP sudo yum install httpd -y
-> Creating partition
ssh -i $Key_location ec2-user@$PublicInstanceIP sudo fdisk /dev/xvdh
- fdisk is the main Linux command for partition related things
- /dev/xvdh is the EBS separate attached volume which is partitioning
- It takes inside the hard disk and there we have to do perform all the partition related steps
- Like which type of partition you want to create primary or extend, size of partition, etc.
-> Format and mount the created partition.
ssh -i $Key_location ec2-user@$PublicInstanceIP "sudo mkfs.ext4 /dev/xvdh1; sudo mount /dev/xvdh1 /var/www/html"
- Here I am running two command through one login.
sudo mkfs.ext4 /dev/xvdh1
- Is to format. mkfs.ext4 is format type and /dev/xvdh1 is partition name.
sudo mount /dev/xvdh1 /var/www/html
- Here I am mounting the same partition with /var/www/html folder which is document root of Apache server.
->Command to create S3 bucket.
aws s3api create-bucket --bucket vishak123 --region ap-south-1 --create-bucket-configuration LocationConstraint=ap-south-1
- Creating bucket with name vishak123
- In the region Mumbai.
-> Command to upload data in S3 with Public Read-Write Permission
aws s3api put-object --acl public-read-write --bucket vishak123 --key $image_path --body $image_path
- This command taking image path dynamically.
Now I stored domain name of S3 vishak123 bucket in a variable
- $s3_domain = "vishak123.s3.ap-south-1.amazonaws.com"
-> Created Cloud Front distribution and stored its url in a variable
$cloudFront_url = aws cloudfront create-distribution --origin-domain-name $s3_domain --query Distribution.DomainName
-> After this i stored html content in a variable.
->Configured webserver by uploading the content first in root folder then by copying in /var/www/html folder
- Before this I transferred html code in a file by following way
echo htmlCodeUrl > Vish_url.html
- Copied in root folder by remote login.
- scp is the command to copy from one OS to other in Linux
scp -i $key_location -r Vish_url.html ec2-user@$PublicInstanceIP:~
- And copied in /var/www/html
ssh -i $Key_location ec2-user@$PublicInstanceIP cp Vish_url.html /var/www/html/index.html
-> And finally started httpd service
ssh -i $Key_location ec2-user@$PublicInstanceIP service httpd start