💥 High Availability Architecture with AWS CLI 💥

Hello Readers!

In this article, we will be looking at how to create High Availability Architecture through 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 an S3 bucket.
  • Finally, place the Cloud Front URL on the web app code for security and low latency.

What is AWS?

Amazon Web Services (AWS) is a secure cloud services platform, offering computing power, database storage, content delivery, and other functionality to help businesses scale and grow. In simple words AWS allows you to do the following things- Running web and application servers in the cloud to host dynamic websites.

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.

DETAILED DESCRIPTION OF THE TASK:

  • Create a key-pair.
  • Launch an EC2 instance.
  • Launch EBS and attach it to launched EC2 Instance.
  • Launch an S3 bucket and upload an object to it.
  • Create a CloudFront Distribution.
  • Configuration of Webserver in EC2 instance.

Let’s move to the task.

First, we will be setting our AWS credentials.

For this, we will use the command

This command will ask aws user access key, secret key, and region where all the resources will be deployed.

Now, we will create a key pair by using AWS CLI.

A key pair, consisting of a private key and a public key, is a set of security credentials that you use to prove your identity when connecting to an instance. Amazon EC2 stores the public key, and you store the private key. You use the private key, instead of a password, to securely access your instances. Anyone who possesses your private keys can connect to your instances, so you must store your private keys in a secure place.

Command to create a key pair:

Now in this step, we will launch an EC2 instance.

Amazon EC2 provides a wide selection of instance types optimized to fit different use cases. Instance types comprise varying combinations of CPU, memory, storage, and networking capacity and give you the flexibility to choose the appropriate mix of resources for your applications.

Command to launch Ec2 instance:

After launching the EC2 instance we will be creating an EBS volume.

An Amazon EBS volume is a durable, block-level storage device that we can attach to our instances.

Command to create EBS Volume:

This command will create an EBS Volume of Size 1GB in the same region where we have our Instance running. the tag-specifications attribute is used to give a name to our volume.

Now, we will attach the volume to the launched instance.

Command to attach the volume:

In this command, we have to give our Instance ID (To which Instance we want to attach with our volume), Volume ID, and device name.

Now, we will launch the S3 bucket and create Cloudfront distribution.

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. Amazon S3 provides easy-to-use management features so you can organize your data and configure finely-tuned access controls to meet your specific business, organizational, and compliance requirements. Amazon S3 is designed for 99.999999999% (11 9’s) of durability, and stores data for millions of applications for companies all around the world.

Command to create an S3 bucket:

Here I have also specified the region by using a region tag.

Now, we will upload anything in the S3 bucket. I have uploaded an Image.

After this, we will create a CloudFront distribution.

Amazon CloudFront is a fast content delivery network (CDN) service that securely delivers data, videos, applications, and APIs to customers globally with low latency, high transfer speeds, all within a developer-friendly environment.

To create CloudFront Distribution command is:

After launching and attaching EBS volume to the launched Instance now we will login remotely into the system and will configure the webserver.

After connecting to the EC2 instance we will install httpd first.

To install httpd on our instance we will be using the yum package installer.

Now, we will create a partition then we will format and mount the EBS volume created in the above step.

Command used to create a partition:

Now, we will mount or volume to the var/www/html folder as all the code of the website resides here only.

To mount command is:

Our volume is mounted now we will write an html file in the /var/www/html location.

Here, I have used <img> tag in html and given the link of the object uploaded in the S3 bucket.

Now, we have to start the httpd service.

To start the httpd service command is:

We can see the output by using the public IP of the Instance and the output image will come from the S3 bucket as we have given the link of the S3 bucket in our html file.

To reduce the latency period we will use CloudFront distribution. We have created CloudFront distribution in the above step we just have to provide the domain name of CloudFront distribution in place of the S3 bucket object link in our html file.

Now, the image in the output is coming through CloudFront distribution.

Thank you for reading this article. Hope this article will be helpful.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Uditanshu pandey

Technical Volunteer at ARTH-The School of Technologies || Cloud Enthusiast || Ansible ||Flutter || Hybrid Multi Cloud || DevOps || Terraform