task Descriptionđź“„

Gjgautamjoshi
6 min readNov 15, 2020

đź”° 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.

FOLLOWING ARE THE STEPS FOR DOING THIS TASK

STEP 1 . FIRST WE INSTALL INSTANCE BY USING THE AWS CLI (COMMAND LINE INTERFACE).

By using the aws cli command by using the key name “gautam”

aws ec2 run-instances — image-id ami-0e306788ff2473ccb — instance-type t2.micro — count 1 — subnet-id subnet-88c8c1e0 — security-group-ids sg-01a248019dab9763a — key-name gautam

here we use by default security group because in future we need to edit the security group because by default means no one allowed to enter but we use

this instance as webserver so that any one can access our website .

by running this command we can launch our instance .

our commands runs successfully now lets by using webui that our instance launched or not .

yes our instance successfully launched .

step 2 . Now we install httpd webserver in this instance

As we install webserver so first we have edit rules of security group so that any can access our website for editing firewall rules we use this command.

After running the command

our command runs sucdessfully .

Security group successfully updated.

we add 80 port no. because webserver works on the 80 port no.

step 2 . Now we install webserver in this instance

we install webserver with help of yum command because in aws instances

yum is already configured.

after running the command

yes, we successfully installed httpd webserver

our next step is to put content of our web pages in this folder

/var/www/html

let’s take a scenerio that by chance if our os get terminated by any mistake then our all codes pages and content also we lost so for solving this problem we attach a EBS volume to our instance so that all our content become safe and we mount this ebs volume to this folder /var/www/html

first we create ebs volume of 1 Gib (it is like a pendrive) with the help of aws cli

with the help of this command.

when we run this command with help of cli .

our command runs successfully now we confim that our volume is created or not with the help of webui of aws

yes it is created and it is ready /available to use .

now our next step is to attach this volume to the instance that we launched in earlier steps .

again this step we do from cli also .

for attaching volume we this command

in this command we give three inputs

first one is our instance id

second is volume id that we create in previous step

third one is device name

after running the command

our command runs successfully now let’s confirm from webu portal that volume is attached or not to the instance.

yes volume is successfully attached to our instance .

now our next step is to mount this volume to this folder

/var/www/html

we also check from fdisk -l command that volume is attached or not

before mounting we have to three steps for using the storage

step 1. create partition

step 2 . format the partition

stop 3 . mount the partiton

first we create the partition by using this command

we successsfully create partition now our next step is to format the partition by using this command

successfully formated the partition now our next is to mount the partiton

to the folder

partition successfully mounted because client always webpage from this folder by default

we can also confirm by using this command

yes it is mounted

our next step is to create bucket in s3 (s3 is a kind of storage for storing objects for eg images ,vedio etc )

we use use s3 for object storage so that we can put link the cloud front so that user can experiance low latency

so first we create bucket in s3 service so that we can put images etc. in this bucket

by using this command we create bucket

bucket created successfully now we check from webui created or not

yes bucket created successfully now we put image in this bucket

with public access

now we uploaded the image successfully

our next step is to put url of image in bucket in s3 in the html code of webpage

after runing the webserver services with the help of

systemctl start webserver command

output comes succesfully .

now our next is setting up the content delivery network with the help of cloud front with the help of cli

now we create distribution in the cloud front

with the help of this command

aws cloudfront create-distribution — origin-domain-name

command runs successfully

we also check from webui

finally we place the cloudfront url in our code

now we again refresh the url check that cloud front url is working or not

yes it is working and our task is done .

--

--