Create High Availability Architecture with AWS CLI

Prasantmahato
4 min readOct 27, 2020

--

Content Delivery Network

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

Created Key-Pair with the help of CLI

I can confirm it by looking onto the Graphical Console.

Successfully created a Key-Pair .

Then created a Security Group .

aws ec2 create-security-group — description “Personal ” — group-name “ arth2020 ”

Created a Security-Group with the help of CLI

I can confirm it by looking onto the Graphical Console.

Successfully created a Security-Group .

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

Created a Instance with the help of CLI .

I can confirm it by looking onto the Graphical Console.

Successfully created a Instance .

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

Remote -login onto Instance .

Installing httpd .

yum install httpd -y

Successfully Installed httpd .

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

Created a partition .

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

Successfully formatted and mounted the partition.

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

Successfully created S3 bucket .

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

Uploaded the file

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

Successfully created a CloudFront

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.

Webapp Code .

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 .

Website is successfully hosted .

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 .

--

--

No responses yet