Creating High Availability Architecture With AWS Cli

Ashish Dwivedi
4 min readMar 21, 2021

--

AWS with Cli

This architecture includes -

  1. Webserver configured on EC2 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
    CloudFront and using the origin domain as S3 bucket.
  5. Finally place the Cloud Front URL on the
    webapp code for security and low latency

1. Webserver configured on EC2 instance

First we will launch an instance for launching instance we will use cli here

aws ec2 -help

We will use this command this will show all available option present for launching instance

aws ec2 run-instances — image-id ami-0533f2ba8a1995cf9 — instance-type t2.micro — count=1 — security-group-ids sg-0f7ebdf82d74664d2 — key-name mykey

Now we will login into this instance for login we have two options

  1. Login via putty (Behind the scene putty also use ssh protocol)

https://www.chiark.greenend.org.uk/~sgtatham/putty/ (link to download putty)

2. Via ssh

aws emr ssh --cluster-id j-3SD91U2E1L2QX --key-pair-file ~/.ssh/mykey.pem

install httpd service

yum install httpd

systemctl start httpd #to start httpd services

2 . Creating EBS volume and attaching it to /var/www/html

To create EBS volume we will use following command

aws ec2 create-volume — availability-zone ap-south-1b — size 1

When we attach volume to the instance it will not attach because of availability zone we have in command we have to use availability zone same where our instance’s availability zone .

aws ec2 create-volume — availability-zone us-east1a — size 1

For attaching created volume to instance

aws ec2 attach-volume — volume-id vol-074e31ac6d9fe58e8 — instance-id i-0637ffb97ef7e8514 — device=/dev/sdf

Now this volume is new so we have to create partition and format the partition and then we will attach volume to file /var/www/html. We have to create partition and format the partition then only the volume is useful to us.

For checking available volume we have command

Fdisk -l

Here we have 1Gib EBS volume attach to our instance “/dev/xvdf” To create partition we have to go inside volume to go inside volume. Command to go inside volume

fdisk /dev/xvdf # (name of storage )

“ n” here used to create new partition then we will use default parameter as input but in size we will define size according to our need here i used default size at last we have to use “w” to save the partition created

Formating partition with mkfs ext4

mkfs.ext4 /dev/xvdf1

Now we will mount this storage (/dev/xvdf1) to var/www/html file

mount /dev/xvdf1 /var/www/html

3. Creating S3 bucket to store static object

aws s3api create-bucket — bucket adtsk-5 — region us-east-1

4. Creating cloud front

aws cloudfront create-distribution — origin-domain-name adtsk-5.s3.amazonaws.co

5. Now we place the Cloud Front URL on the
webapp code for security and low latency

After using this url in webapp when we go to our web page with ip it will show static image.

--

--

No responses yet