High Availability Architecture with AWS CLI

Naveen Pareek
7 min readJul 28, 2021

--

The AWS Command Line Interface ( CLI ) is a unified tool to manage your AWS services.

After downloading and configuring only one tool, we can control multiple AWS services from the command line and automate them through scripts.

We can use AWS services in three of the following ways:-

⚫ WebUI.
⚫ Command Line Interface (CLI).
⚫ Automation through scripts.

Why do we use AWS CLI?

⚫ In WebUI, we cannot launch two instances at different subnets at the same time.
⚫ CLI is automatable.
⚫ Real developers don’t use GUI!

Before performing this task we should know about the given services of AWS Cloud:

What is AWS?

Amazon Web Services (AWS) is the world’s most comprehensive and broadly adopted cloud platform, offering over 175 fully-featured services from data centers globally. Millions of customers — including the fastest-growing startups, largest enterprises, and leading government agencies — are using AWS to lower costs, become more agile, and innovate faster.

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.

What is 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.

What is S3?

Object storage is built to store and retrieve any amount of data from anywhere. Get started with Amazon S3. Request more information. Amazon Simple Storage Service (Amazon S3) is an object storage service that offers industry-leading scalability, data availability, security, and performance.

What is CloudFront?

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.

Now let's begin with the task !!

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.

Creating IAM users so that we can use AWS CLI

Creating New IAM User

Installing the AWS CLI

First, we need to download and install the AWS CLI software:

https://awscli.amazonaws.com/AWSCLIV2.msi

After the installation is complete we need to configure our CLI by provisioning it with the access and secret key to authenticate our account. The access and secret key can be obtained in the security settings for the root user (not preferred) or by creating an IAM user for the same purpose (preferred). We also need to specify the availability zone in which we want to work.

Step 1: Configure the AWS Command Line Interface (AWS CLI).

Configuring AWS CLI for IAM User

Step 2: Create a new Key Pair using an AWS CLI, and save the private key with the .pem extension.

Create Key-Pair via AWS CLI
Key Pair AWS Console output

Step 3: Create a Security Group which we named SGforCLI. And, then add the Inbound Rules, where we allowed all traffic using the AWS CLI.

Creating a new Security Group and set Inbound rules for All traffic
AWS management console output of Security Groups
Newly created Security Group AWS management console output with Inbound rule to All traffic.

Step 4: After the successful creation of Key-Pair and Security Group, now it's time to launch an EC2 Instance via AWS CLI.

To create the EC2 instance using the AWS CLI. We need the following information:
🔺Image-id
🔺Instance-type
🔺Subnet-id
🔺Security Group Id
🔺Key-Pair Name
Command to launch a new instance
console output after successful execution of AWS CLI command
AWS management console of EC2 Instance
EC2 Instance details that we have used the above-created resources.

Step 5: Create the EBS volume of 1GB in the region where the EC2 instance is created.

Command to create an EBS volume via AWS CLI
AWS management console output of newly created EBS volume

Step 6: After launching both EC2 instance and EBS Volume, now we need to connect them with each other.

For Attaching EBS Volume with EC2 Instance, we need following information:
🔺Instance ID.
🔺Volume ID.
Command to attach EC2 Instance with EBS volume
Console Output of EBS volume attached with EC2 Instance
AWS management console proof of attached EBS volume with EC2-instance.

Step 7: Now, Log-in to the EC2 instance using SSH Protocol.

command to connect with EC2 instance using ssh is:
ssh -i “ArthTaskKey.pem” ec2-user@15.206.27.37
Command to connect with AWS Instance via SSH.

Step 8: Now we need to format, partition, and mount the connected EBS volume to the folder (document root directory of the webserver) in an instance.

Check the partitions available in the instance using “fdisk -l” command.

command to check partitions available in the instance.

Format the complete disk, if no partition is available in the attached EBS disk using command “mkfs.ext4 /dev/xvdf”.

command to format the entire attached Volume before creating any partitions.

After successful formatting the disk, create the partitions in the disk using command “fdisk /dev/xvdf”.

complete steps for creating partitions over newly attached volume.

Check the partitions using the command “lsblk”.

command to check whether a partition is created or not.

Again, format the recently created partition.

format the newly created partition over the volume attached.

Step 9: After completing the previous step now it’s time to set up the httpd server.

We need to install the httpd web server using the command “yum install httpd”.

shows how to install the httpd web server in a Linux OS.

Configure the webserver and then mount the document root directory of the web server over the newly created partition in EBS volume.

shows complete steps of mounting document root on a newly created partition.

Step 10: To store any object like images, videos, files, etc., we are creating an S3 Bucket via AWS CLI.

command to create a bucket in s3
AWS management console of s3.

Upload the file via AWS Management Console and then give the public access to that bucket.

Uploading file in the s3 bucket
Giving Public Access to S3 bucket
File successfully uploaded.

Step 11: Setting up Content Delivery Network as CloudFront and use the origin domain as S3 bucket.

Command to create CloudFront Distribution
AWS management console of CloudFront
Details of newly created CloudFront Distribution.

Step 12: Finally, place the Cloud Front Distributed Domain URL in the web app code for security and low latency and then enjoy the Web Service without any problem.

Final outcome of this task.

Hurray!! We have successfully completed the entire task.

Thank You!

Keep Learning & Sharing…

If this article is useful for you then don’t forget to press the clap 👏 icon and also follow me on medium for more such amazing articles.

Leave a comment if you have any doubts or you can connect me on LinkedIn.

--

--

No responses yet