??High Availability Architecture with AWS CLI???

Have you ever wonder that how the Big Companies website’s just like Amazon Prime Video, JioSaavn, Slack, Marriott International always have dynamic data on their sites? 

Or ever come’s in your mind that how these sites provide low latency and gives Best-User Experience worldwide ??

If yes, then this Article will help you to know about the internals of their sites that what services they use & how these sites manage low latency and provide best-user experience.

So, these companies uses Amazon Cloud Front as a service which is provided by AWS for low latency and best-user experience on their websites.

What is Amazon CloudFront ?
  • 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. 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.
  • If the content is already in the edge location with the lowest latency, CloudFront delivers it immediately.
  • If the content is not in that edge location, CloudFront retrieves it from an origin that you’ve defined — such as an Amazon S3 bucket, a MediaPackage channel, or an HTTP server (for example, a web server) that you have identified as the source for the definitive version of your content.
No alt text provided for this image

Lets Understand this by creating an Architecture:

  • 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 Lets start creating this Architecture and understanding the concepts:

1.) What is AWS ?

Amazon Web Services (AWS) is a secure cloud services platform, offering compute power, database storage, content delivery and other functionality to help businesses scale and grow. It provides each service at a minimal cost.

In this practical I’m going to use AWS CLI, EC2, EBS, S3 and CloudFront service of AWS. We’re going to do the complete practical using CLI not GUI, which makes the task more interesting.

No alt text provided for this image
2.) What is AWS CLI?

The AWS Command Line Interface (CLI) is a unified tool to manage your AWS services. With just one tool to download and configure, you can control multiple AWS services from the command line and automate them through scripts.

2.1) How to install AWS CLIv2

  • Download the AWS CLI MSI installer for Windows (64-bit): https://awscli.amazonaws.com/AWSCLIV2.msi
  • Run the downloaded MSI installer and follow the on-screen instructions. By default, the AWS CLI installs to C:\Program Files\Amazon\AWSCLIV2.
  • To confirm the installation, open the Start menu, search for cmd to open a command prompt window, and at the command prompt use the aws — version command.
C:\Users\user>aws --version

aws-cli/2.0.59 Python/3.7.7 Windows/10 exe/AMD64

2.2) How to configure AWS CLIv2 ?

  • Open the command prompt in Windows and execute the following command & enter then enter the access key ID, secret access key and availability zone and set the output format to default i.e. json.
No alt text provided for this image

Now, let’s launch an instance!

3.) What is Amazon EC2?

Amazon Elastic Compute Cloud (Amazon EC2) is a web service that provides secure, resizable compute capacity in the cloud. It is designed to make web-scale cloud computing easier for developers. Amazon EC2’s simple web service interface allows you to obtain and configure capacity with minimal friction. It provides you with complete control of your computing resources and lets you run on Amazon’s proven computing environment.

3.1) Launching an EC2 instance using AWS CLI.

An instance is a virtual server in the cloud. Its configuration at launch is a copy of the AMI that you specified when you launched the instance. You can launch different types of instances from a single AMI.

for launching the instance, we need ami image id , instance type, subnet id ,security group id, key name and the number of counts.

So collect all this info in a file from aws webui and then run the command:

 aws ec2 run-instances --image-id <id> --instance-type <type> --subnet-id <id> --security-group-ids <id> --key-name <name> --count <num_of_count> 
No alt text provided for this image

The following instance will be launched:

No alt text provided for this image

Now, let’s create a 1 GB volume and attach it!

4.) What is Amazon EBS?

Amazon Elastic Block Store (EBS) is an easy to use, high performance block storage service designed for use with Amazon Elastic Compute Cloud (EC2) for both throughput and transaction intensive workloads at any scale.

4.1) Create EBS Volume through CLI

  • Run the following command in the command prompt to create an EBS volume of 1 GB:
aws ec2 create-volume  --availability-zone ap-south-1b --size 1 --volume-type gp2
  • The following volume has been created, note the Volume ID, we will need it to attach the volume
No alt text provided for this image

4.2) Attach EBS Volume through CLI

  • Run the following command in the command prompt to attach the EBS volume to EC2 instance:
aws ec2 attach-volume   vol-09b44f65561a6a2f1 --instance-id i-08e9c11ed7385049b --device /dev/sdf
No alt text provided for this image
  • The volume is attached to our EC2 instance
No alt text provided for this image
5.) How to configure the webserver?
  • Login your instance using Putty
  • Execute the following command in the command prompt of your instance:
sudo yum install httpd
No alt text provided for this image
  • To start the service of httpd, execute the following command:
 systemstl start httpd
 systemstl status httpd
No alt text provided for this image

We’ve successfully configured the webserver & started it’s services.

Now, let’s create partition in our volume!

5.1) How to create, format & mount partition?

  • To check the status of your disk, execute the following command in your command prompt:
 fdisk -l
No alt text provided for this image
  • To create a partition in the volume, use these steps:
 fdisk /dev/xvdf
  • Create a primary partition as follows:
No alt text provided for this image
No alt text provided for this image
  • Use the following command for giving driver to the partition:
 udevadm settle
  • Use the following command to format the partition:
 mkfs.ext4 /dev/xvdf1
No alt text provided for this image
  • I used the following command to mount my partition on /var/www/html directory:
 mount /dev/xvdf1 /var/www/html
No alt text provided for this image

Now that we’ve created, formatted & successfully mounted our partition, let’s move on to create a S3 bucket

6.) What is Amazon S3?

Amazon Simple Storage Service (Amazon S3) is an object storage service that offers industry-leading scalability, data availability, security, and performance. This means customers of all sizes and industries can use it to store and protect any amount of data for a range of use cases, such as data lakes, websites, mobile applications, backup and restore, archive, enterprise applications, IoT devices, and big data analytics.

6.1) How to create a S3 bucket?

Execute this command to create a S3 bucket with public access, public access is important to let our webpage be displayed to everyone:

aws s3api create-bucket --bucket my-bucket --region eu-west-1 --create-bucket-configuration LocationConstraint=eu-west-1
No alt text provided for this image
  • We can check the result using Amazon GUI as well:
No alt text provided for this image

6.2 ) How to upload files into this S3 bucket?

  • Execute the following command to upload the files of a folder into our bucket:
aws s3 sync "C:\Users\user\Desktop\Spotify.jpg" s3://mananbuckettask6 --acl public-read

As we can see, the two files have been uploaded into our S3 bucket with read access to the public:

No alt text provided for this image

6.3) Creating CloudFront Distribution !

Let’s now create a distribution in CloudFront by using the following command:

No alt text provided for this image

This is my CloudFront Distribution:

No alt text provided for this image

My HTML Code. This file is created inside /var/www/html directory:

No alt text provided for this image

And here is the final output!!!

No alt text provided for this image

Link for the webpage: https://52.66.211.176/test.html

To see the cache statistics of the distribution:

No alt text provided for this image

Total Hits: Total number of times someone accessed the webpage

Total Misses: Total number of times the image in the webpage was not present at the edge location

Total Errors: Total number of times the webpage didn’t display

Now, Anyone can access this site across the worldwide without any delay because we have used CloudFront service for AWS for low latency and for High Availability !

I hope you like the Article and find it useful. Any queries and suggestions are highly accepted !!

Keep Learning, Keep Growing ??

Thankyou!!??

Rahul Prajapati

Cloud Engineering @ Alteryx | 3x GCP | Ex - AirAsia

4 年

Well explained ??

回复
Amit Sharma

CKA || 1xAWS || 4xGCP || 1xAzure || 2xRedHat Certified || DevOps Engineer [???????]@Searce Inc || Freelancer || Terraform || Ansible || GitLab || Jenkins || Kubernetes || Docker || Openshift || AWS || GCP || Azure

4 年

Nice ??????

回复

要查看或添加评论,请登录

Manan Jain的更多文章

  • Music Recommendations at Spotify

    Music Recommendations at Spotify

    Spotify is a music streaming industry started in 2006. It got its first official launch in India in February 2019 and…

社区洞察

其他会员也浏览了