Create High Availability Architecture with AWS CLI

Create High Availability Architecture with AWS CLI

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.

TASK DESCRIPTION:

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

❗❗All the above steps must be performed using AWS CLI ❗❗

Now let’s start to practical part:

🔅 Webserver configured on EC2 Instance

Firstly will create a new key pair using this command :

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

No alt text provided for this image

Goto aws ec2 dashboard and to check new key

No alt text provided for this image

Create a security group 

To create a security group using following command:-

aws ec2 create-security-group --group-name ”GROUP_NAME" --description "DSCP"

No alt text provided for this image

To check security group is created or not, go to ec2 dashboard then click on security groups

No alt text provided for this image

Now, We have to launch one EC2 instance using above created key-pair and the security group using following command:

aws ec2 run-instances --image-id <image id> --instance-type <type> --count <number> --subnet-id <subnet-id> --security-group-ids <security-group-id> --key-name <key name>

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

To check create new instance or not.

No alt text provided for this image

So 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


No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

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

Here firstly we will create a EBS volume using this command :

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

No alt text provided for this image

To check EBS is created or not.

No alt text provided for this image

Now we will attach this EBS volume to our instance using this command :

aws ec2 attach-volume --volume-id <vol id> --instance-id <instance id> --device <name of device>

No alt text provided for this image

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

Using fdisk -l we can verify EBS volume is attached or not.

No alt text provided for this image

To creating partitions we use command fdisk /dev/xvdf 

Then press p for primary partition and press n to create a new partition then press w to save it.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

To Format this volume use mkfs.ext4 /dev/xvda1

No alt text provided for this image

To connect new hard disk to O.S or 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

No alt text provided for this image

🔅 Static objects used in code such as pictures stored in S3

Firstly we have to create a S3 bucket using following command:

aws s3api create-bucket --bucket <name> --region <region> --create-bucket-configuration LocationConstraint=<region>

No alt text provided for this image

To upload any file to S3 bucket use this command:

aws s3 cp <path> s3://<bucketname> --acl public-read

No alt text provided for this image

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.


No alt text provided for this image

🔅 Setting up Content Delivery Network using CloudFront and using the origin domain as S3 bucket.

Firstly we have to set up Content Delivery Network using CloudFront in Amazon-CLI by this command:

aws cloudfront create-distribution --origin-domain-name <name of bucket>.s3.amazonaws.com

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Finally, our webapp is created with High Availability Architecture.

Thank you for reading !!


To view or add a comment, sign in

More articles by Anant Prakash Sharma

Others also viewed

Explore content categories