High Availability Architecture with AWS CLI
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
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).
Step 2: Create a new Key Pair using an AWS CLI, and save the private key with the .pem extension.
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.
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
Step 5: Create the EBS volume of 1GB in the region where the EC2 instance is created.
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.
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
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.
Format the complete disk, if no partition is available in the attached EBS disk using command “mkfs.ext4 /dev/xvdf”.
After successful formatting the disk, create the partitions in the disk using command “fdisk /dev/xvdf”.
Check the partitions using the command “lsblk”.
Again, format the recently created partition.
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”.
Configure the webserver and then mount the document root directory of the web server over the newly created partition in EBS volume.
Step 10: To store any object like images, videos, files, etc., we are creating an S3 Bucket via AWS CLI.
Upload the file via AWS Management Console and then give the public access to that bucket.
Step 11: Setting up Content Delivery Network as CloudFront and use the origin domain as S3 bucket.
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.
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.