High Availability Architecture with AWS CLI

Kumawatpayal
5 min readOct 31, 2020
CloudFront

Task Description —

🔰 Create High Availability Architecture with AWS CLI 🔰

The 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. Launching EC2 Instance Using CLI command

First, we are going to launch an ec2 instance by using the key-pair and security group which are created by aws cli command, and the command for The Key-Pair Cli Command —

aws ec2 create-key-pair — key-name LwFirstKey

create key-pair

The Security-Group Cli Command —

aws ec2 create-security-group — group-name LwFSgroup — description “My LwF Security Group”

create security group

We are creating an instance so that we can easily configure our webserver to deploy our website.

The Ec2 Instance Cli Command —

aws ec2 run-instances — image-id ami-0e306788ff2473ccb — count 1 — instance-type t2.micro — key-name LwFirstKey — security-group-ids sg-008226d80561bced0 — subnet-id subnet-52141d3a

create instances

2. Create And Attach EBS Volume to instance

We are creating an external EBS Volume so that we can store or save our code and data in persistent storage. EBS is a block storage service provide by AWS.

Why we used EBS Storage for storing our code, because Its provide 99.999% availability of our data. Here, Availability means if our system crash due to failure of any single hardware component your data will never loss aws says i give you 99.999% surety. Its also provide data persistence facility.

The Command For EBS Volume Creation —

aws ec2 create-volume — availability-zone ap-south-1a — size 10 — volume-type gp2

EBS Volume Creation

EBS Volume Attach Command —

aws ec2 attach-volume — volume-id vol-0b1f7da458e2018d5 — instance-id i-06f060131492f6bd5 — device /dev/sdf

EBS Volume Attach

3. Create Partition, Format the EBS Volume, and Mount the Folder over it

Now, we are going to create a partition on the Volume then format the external Volume and mount our folder.

fdisk -l command is used to check the attached disk.

After that, use fdisk /dev/xvdf(disk name) command for go inside the disk.

In the below image we used partition command for creating partition. disk provides own command for creating partition.

n command used for new partition, after that used p command for primary partition and then provide partition size and then finally used w command for save the partition.

partition created

After Creating partition, we need to format the partition.

The format command — mkfs.ext4 /dev/xvdf1

ext4 is format extension, in linux we have various extension.

format partition

The mount command — mount /dev/xvdf1 /var/www/html

mounting the folder

4. Creating S3 Bucket using CLI command

Now, We are going to create S3 Bucket So that we can store our static object, images, pdf file etc.S3 is a object storage provided by AWS . S3 provides public access so that we can retrieve our data from anywhere. S3 provides 99.999999999% durability of our data.

The Command For Creating S3 Bucket —

aws ec2 create-bucket — bucket lwf-bucket — region ap-south-1 — create-bucket-cofiguration LocationConstraint=ap-south-1a

create S3 Bucket

In the below image you can see the bucket.

by using aws s3 ls command you can see the list of bucket.

list of bucket

5. Copying the data(image) to the s3 bucket

The Command For Upload the file into bucket from local system-

aws s3 cp {local file path}s3: {bucket-name} — acl public-read

upload a image and give public access

6. Creating CloudFront Distribution

we are going to create a cloudFront Distribution for high speed and low latency.

Aws provides their own secure global private infrastructure under the content delivery network service(Distribution service). In this service Aws provide edge location(mini data center) where Aws store the caches of our data for high speed and low latency.

The Command for CloudFront-

aws cloudfront create-distribution — origin-domain-name lwf-bucket.s3.amazonasw.com

create distribution

7. Configuring webserver

For webserver configuration we need to follow some command-

  1. yum install httpd by using this command install apache server.
  2. systemctl enable httpd by using this command start server permanently.
  3. cd /var/www/html go inside this folder and create our html file.
  4. vi index.html and then write some html code.
  5. Final Result —

--

--