Created High Availability Architecture with AWS CLI

Tejas Sanghai
4 min readMar 21, 2021

Hello Everyone!!

In this article I have done following task using AWS CLI

  1. Webserver configured on AWS instance
  2. Document root(/var/www/html) made persistent by mounting on EBS block device.
  3. Static objects used in code such as pictures stored in S3
  4. Setting up content delivery network using cloud front and using the origin domain as S3 bucket
  5. Finally place the cloud front URL on the WebApp code for security and low latency.

So, First of all we will launch one instance on AWS cloud using CLI of our windows system

To launch Instance — “aws ec2 run-instances — image-id ami-ami-068d43a544160b7ef — subnet-id subnet-1cd6df74 — instance-type t2.micro — key-name AWSkey — security-group-ids sg-05df0abdf0e9617c4 — count1

and also for check if the instance is launched or not you can check that on the AWS management console >> EC2 Dashboard

Now, we have successfully launched instance now we have to attach the external volume to it for that you have create on volume of any space by going into console

then to attach that volume to the instance — “aws ec2 attach-volume — volume-id vol-0f1cac78c3be4f206 — instance-id i-0acf9261b38a782c8 — device /dev/svdf

Now , we have also successfully attached volume to our instance.

Next we have to Connect the instance and start it and we have to install httpd software on it

To install httpd — yum install httpd

Next we have to do is Partition , Formatting of disk and mounting of new disk

For partition — “fdisk /dev/xvdf

For Formatting — “mkfs.ext4 /dev/xvdf1

For Mounting — Remember we have to mount that disk on /var /www/html

so for that — “mount /dev/xvdf1 /var/www/html

Now, Check once that you have httpd installed

To check — rpm -q httpd

Now Creation of S3 bucket on AWS using Command prompt of windows

To create S3 storage bucket — “aws s3api create-bucket — bucket myvolume — region ap-south-1 — acl public-read — create-bucket-configuration LocationConstrained=ap-south-1

And now upload one picture on AWS S3 bucket through CLI

For that — “aws s3 cp C:\Users\tsang\Downloads\Tejas.png s3://myvolume — acl public-read

Setting-up Content Delivery Network using CloudFront with S3 bucket as Domain origin

To create -”aws cloudfront create-distribution — origin-domain-name myvolume.s3.amazonaws.com

Now create one file .html file to inside the /var/www/html

and check whether httpd services are running

systemctl start httpd

systemctl status httpd

Now Click on the public IP of your Instance you should see your html code on webpage

Thank You!!!!!

--

--