High Availability Architecture with AWS CLI

Sanjana VK
7 min readNov 2, 2020

🔅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.

So before we start our task let’s learn about few terminologies:

📌What is Web Server?

A web server is a system that delivers content or services to end users over the internet. A web server consists of a physical server, server operating system (OS) and software used to facilitate HTTP communication. The most simple definition is that a web server runs a website by returning HTML files over an HTTP connection. This definition may have been true in the early days of the internet, but the line has blurred between websites, web applications and web services,etc.

📌What is EC2 instance?

EC2 (Elastic compute cloud) is Amazon’s one of the most popular offerings. The EC2 instance is a virtual server or machine, you can use to deploy your application. It comes under IAAS (infrastructure as a service). EC2 service capabilities are related to Computing, Storage and Network on rent.

📌What is EBS Volume ?

EBS stands for Elastic Block Store.EC2 is a virtual server in a cloud while EBS is a virtual disk in a cloud. Amazon EBS allows you to create storage volumes and attach them to the EC2 instances. Once the storage volume is created, you can create a file system on the top of these volumes, and then you can run a database, store the files, applications or you can even use them as a block device in some other way. Amazon EBS volumes are placed in a specific availability zone, and they are automatically replicated to protect you from the failure of a single component.EBS volume does not exist on one disk, it spreads across the Availability Zone. EBS volume is a disk which is attached to an EC2 instance.EBS volume attached to the EC2 instance where windows or Linux is installed known as Root device of volume.

📌What is S3 Storage?

Amazon S3 (Simple Storage Service) provides object storage, which is built for storing and recovering any amount of information or data from anywhere over the internet. It provides this storage through a web services interface. While designed for developers for easier web-scale computing, it provides 99.999999999 percent durability and 99.99 percent availability of objects. It can also store computer files up to 5 terabytes in size. Some of the benefits of AWS S3 are: Durability, Low cost, Scalability, Availability, Security, Flexibility, Simple data transfer.

📌What is Cloud Front?

Cloud Front is a CDN (Content Delivery Network). It retrieves data from Amazon S3 bucket and distributes it to multiple datacenter locations. It delivers the data through a network of data centers called edge locations. The nearest edge location is routed when the user requests for data, resulting in lowest latency, low network traffic, fast access to data, etc.

Let’s begin with the task:

🚩WebServer configured on EC2 instance:

✔The first step we have to do is launch an EC2 instance using the AWS cli. We can make use of the existing key pair we used in the last task.

#aws ec2 run-instances — image-id <image_id> — count<count> — instance-type<type of instance> — key-name<existing_keyname> — security-group-ids<id> — subnet-id<subnet id>

✔Now we have to configure the web server on the EC2 instance we created using the commands:

#yum install httpd

Will install httpd software

#systemctl start httpd

Will start the services of the webserver

#systemctl status httpd

Checks whether it is active or inactive

#systemctl enable httpd

Permanently starts the services of webserver

So we have created an EC2 instance and configured webserver in it.🤩

🚩Creating an EBS volume and mounting it on Document root(/var/www/html):

✔The first thing we have to do is create an EBS volume

#aws ec2 create-volume — volume-type<type> — size<size> — availability-zone<zone>

⚠Create the ebs volume in the same zone where you have created your ec2 instance.

✔Next step is to attach the EBS Volume to EC2 instance we created,

#aws ec2 attach-volume — volume-id<id> — instance-id<id> — device /dev/sdf

✔Now we have to mount our EBS volume ,to do this we have to create a partition and then format it.

Before partitioning we have to check if EBS volume is attached or not using the command

#fdisk -l

To create partition

#fdisk /dev/xvdf

then press p (to create primary partition)>press n(to create a new partition)>press w(save the partition)

To format the partition

#mkfs.ext4 /dev/xvdf1

We have to connect our new hard disk to OS through a driver so we use

#udevadm settle

To mount the EBS volume on document root

#mount /dev/xvdf1 /var/www/html

To check we use

#df -h

✔Next step is we have to create a html file in /var/www/html

#cd /var/www/html

#vi text.html

🚩Store the static object in S3 storage:

Static object is an object that persists from the time it’s constructed until the end of the program. They are called automatic or local objects.Static objects are allocated storage in static storage area like S3,EBS .

A query might arise here that why do we use S3 to store a image or video instead of EBS storage? This is because of it’s durability.

✔We have to create a S3 bucket and provide public access

#aws s3api create-bucket — bucket<bucket_name> — region<region> — ac1 public read — create-bucket-configuration LocationConstraint=<region>

✔Next step is to upload a image in S3 bucket

#aws s3 cp <local path> s3://<bucket-name> — ac1 public-read

✔The link we will get after uploading the image in the bucket is used in html code.

Even though we store image in S3 storage we still have a few disadvantages like low latency and low-speed data transfer.So to eliminate these disadvantages we make use of CLOUDFRONT which is a concept based on Content Delivery Network(CDN).

🚩Setting up content delivery network using cloud front and using the url in the html code:

✔Creating Cloud Front using the command

#aws cloudfront create-distribution — origin-domain-name <image_name>.s3.amazonaws.com

✔Use the domain name in the html code

Finally we have created our webpage🌟🌟

We can see the webpage using the url:

http://ip_address/file_name

So I hope you guys learnt something. Thank you for reading.😀😀

--

--