← Create High Availability Architecture with AWS CLI →

Gowniriteshreddy
7 min readNov 14, 2020

→What is a Web-Server?

  • A web server is software and hardware that uses HTTP (Hypertext Transfer Protocol) and other protocols to respond to client requests made over the World Wide Web. The main job of a web server is to display website content through storing, processing and delivering webpages to users. Besides HTTP, web servers also support SMTP (Simple Mail Transfer Protocol) and FTP (File Transfer Protocol) used for email, file transfer and storage.
  • Web server hardware is connected to the internet and allows data to be exchanged with other connected devices, while web server software controls how a user accesses hosted files. The web server process is an example of the client/server model. All computers that host websites must have web server software.
  • Web servers are used in web hosting, or the hosting of data for websites and web-based applications or web applications.

→What is EBS?

  • Elastic Block Store (EBS) is a block storage service based in the AWS cloud. EBS stores huge amounts of data in blocks, which work like hard drives (called volumes). You can use it to store any type of data, including file systems, transactional data, NoSQL and relational databases, backup instances, containers, and applications. EBS is usually used for
  • EBS is offered through the AWS platform, and requires an AWS account. The platform enables you to optimize performance and pricing. For example, you can change the volume size and type, and delete redundant volumes. From the platform, you can configure backup and recovery options for your data.

→What is S3 bucket?

  • S3 bucket is a public cloud storage resource available in Amazon Web Services’ (AWS) Simple Storage Service (S3), an object storage offering. Amazon S3 bucket, which are similar to file folders, store objects, which consist of data and its descriptive metadata.

→What is Cloud Front ?

  • Amazon CloudFront is a web service that speeds up distribution of your static and dynamic web content, such as .html, .css, .js, and image files, to your users.

→How does cloud Front Work?

  • CloudFront delivers your content through a worldwide network of data centers called edge locations. When a user requests content that you’re serving with CloudFront, the user is routed to the edge location that provides the lowest latency (time delay), so that content is delivered with the best possible performance.

→What is a CDN?

  • A content delivery network (CDN) refers to a geographically distributed group of servers which work together to provide fast delivery of Internet content.
  • A CDN allows for the quick transfer of assets needed for loading Internet content including HTML pages, javascript files, stylesheets, images, and videos. The popularity of CDN services continues to grow, and today the majority of web traffic is served through CDNs, including traffic from major sites like Facebook, Netflix, and Amazon.

→How does a CDN work?

  • At its core, a CDN is a network of servers linked together with the goal of delivering content as quickly, cheaply, reliably, and securely as possible. In order to improve speed and connectivity, a CDN will place servers at the exchange points between different networks.
  • These Internet Exchange Points(IXPs) are the primary locations where different Internet providers connect in order to provide each other access to traffic originating on their different networks. By having a connection to these high speed and highly interconnected locations, a CDN provider is able to reduce costs and transit times in high speed data delivery.

→ I’m doing this article to show the following:

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

→ Now lets start the task.

- Webserver configured on EC2 Instance

> First create a keypair in your command prompt as you saw in my previous article.

aws ec2 create-key-pair - -key-name<any name>

  • Check in your AWS console.

> Then create a security group.

aws ec2 create-security-group - -group-name <any name> - -description <any description>

  • Check in your AWS console.

> Now launch an EC2 instance using the above created keypair and security group.

aws ec2 run-instances — image-id ami-0e306788ff2473ccb — instance-type t2.micro — count 1 — subnet-id subnet-973f36ff — security-group-ids sg-034f3639ec5c5637b — key-name webserver_config

  • Check in your AWS console.

→ Let’s now configure this instance as web server

> For configuring the webserver on Ec2 instance we have to install httpd software which is a product of Apache. Following are the commands to install webserver :

yum install httpd

systemctl start httpd

systemctl status httpd

systemctl enable httpd

🔰 Document Root(/var/www/html) made persistent by mounting on EBS Block Device.

  • Now we will create a EBS volume using the following command :

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

→ Check in your AWS console.

  • Now attach this EBS volume to our instance using the following command :

aws ec2 attach-volume — volume-<available in your console> — instance-id i-<available in your console>— device /dev/sdf

→ Check in your AWS console that it is attached or not.

→Now we have to do Partitions, format, and mount our attached EBS volume.

→Use the following command:

fdisk -l

  • To create partitions use the following command:

fdisk /dev/xvdf

→Then enter ‘p’ for primary partition and ‘n’ to create a new partition then ‘w’ to save it.

To Format this volume use

mkfs.ext4 /dev/xvda1

  • To connect new hard disk to the instance we need a driver. For driver we use:

udevadm settle

  • To Mount this volume to Document Root Folder i.e /var/www/html we use:

mount /dev/xvdf1 /var/www/html

🔰 Static objects used in code such as pictures stored in S3:

  • Now we have to create a S3 bucket using following command:

aws s3api create-bucket — bucket webserverconfig — region ap-south-1 — create-bucket-configuration LocationConstraint=ap-south-1

  • Check the S3 bucket in console.

→ To upload any file to S3 bucket use the following command:

aws s3 cp C:\Users\G.RITESH REDDY\Desktop\aws cli.png s3://webserverconfig - - acl public-read

→ Now we have successfully saved our static data to the S3 bucket. We can use the link of our file to add in our HTML code.

Now let’s run our web page : [public id of instance/filename.html]

→ Thanks for reading……

--

--