Create High Availability Architecture with AWS CLI
Webserver configured on EC2 Instance
To Configure a Webserver ,I have created a EC2 Instance with the help of CLI ,
First I created a Key pair .
aws ec2 create-key-pair — key-name key2
I can confirm it by looking onto the Graphical Console.
Then created a Security Group .
aws ec2 create-security-group — description “Personal ” — group-name “ arth2020 ”
I can confirm it by looking onto the Graphical Console.
Now I created a Instance on CLI with the key-pair and security-group which I have created earlier .
aws ec2 run-instances — image-id ami-0e306788ff2473ccb — instance-type t2.micro — key-name key2 — security-group sg-0312d09ce52608c1c — subnet-id baceb1f6 — count 1
I can confirm it by looking onto the Graphical Console.
Document Root(/var/www/html) made persistent by mounting on EBS Block Device.
Remote login onto the instance and Installing Httpd webserver .
ssh 15.207.223.99 -i mykey.pem -l ec2-user
Installing httpd .
yum install httpd -y
Now we attach or mount document root (/var/www/html) to external EBS volume so that if the Instance by chance crashes or anything happens there would recovery of our code in the external block storage .
To mount any storage we need to do in following three steps
First create a partition .
We can get this option by the command
fdisk devicename
Now we have to format that would be the second step and then mount that would be the third step .
I mounted to document root file
mount /dev/xvdh1 /var/www/html
Static objects used in code such as pictures stored in S3
As our one of the object on the website is static so to make it persistent ,I have created a S3 bucket and stored the object there .
Created bucket by using
aws s3api create-bucket — bucket arth4231 — region ap-south-1 — create-bucket-configuration LocationConstraint = ap-south-1
I can confirm it by looking onto the Graphical Console.
Uploaded file in the S3 bucket
aws s3 cp arth2020.png s3://arth4231/ — acl public-read-write
Setting up Content Delivery Network using CloudFront and using the origin domain as S3 bucket.
Now actually we have created a backup we can directly get the public link and attach to the website code ,But now the only issue is to be faced by client is latency and inorder to lower the latency we need CDN(Content Deleivery Network ) as a service And AWS provides with this service named CloudFront .
So to create a Cloudfront we need a Origin source that we had created previously as S3 Bucket .
Creating a CloudFront distribution.
aws cloudfront create-distribution — origin-domain-name arth4231.amazonaws.com
Finally placed the Cloud Front URL on the webapp code for security and low latency.
Now the link provided by the Cloudfront I have attached to the Webpage code. and started the HTTP daemon.
Now the content cache is there in every Edge location .First time it would give latency but next time it will take content from nearby Edge location cache to reduce latency and give more security .
Thank you so much Vimal daga sir for this beautiful task .
If you any problem related , dm me .I would be happy to explain you .