Create High Availability Architecture with AWS CLI
By: Shubham Rasal
Tags: Deployment, Aws Ec2, Cloud Computing, AWS, Web Development

AWS -11

Create High Availability Architecture with AWS CLI

We are going to create the above architecture using AWS CLI. Let’s discuss architecture and how we are going to do it?

🔶The architecture includes-

◼️ Launch EC2 instance

◼ Create EBS volume

◼Mount EBS volume to EC2 instance

◼Create an S3 bucket

◼Upload static objects such as images, videos, or documents in the S3 bucket

◼Create a content delivery network (CDN) using aws CloudFront distribution for S3 bucket

◼️️ Configure instance as the webserver

◼Place CloudFront URL in an application for security and low latency

◼Deploy source code on EC2 instance webserver.

The final goal is to achieve all these tasks using AWS CLI without going to the website and manual clicks.

If you are very new to AWS CLI, I would like you to check out the basic introduction to AWS CLI

Action Mode 🔥

I am assuming that you have created an IAM user that has EC2, CloudFront, and IAM access and configured AWS CLI.

Create Key Pair

To create keypair we have to use the ec2 service of AWS. by using

$ aws ec2 help

you will see all the subcommands under ec2.

To create a key pair and save it in the proper format(.pem), use the below command.

Note: Windows users use PowerShell for the above commands. To activate PowerShell on normal cmd. Enter $ PowerShell command. OR Win + R and enter PowerShell to open Powershell.

Create a Security Group

You may want to create a security group in a specific VPC. For that, we need a vpc id. Let’s find the VPC id using AWS CLI.

the above command will return the list of VPC’s and tags associated with VPC.

copy the vpc id you want to create SG in and save it somewhere.

Now let's create a security group.

Don't forget to edit the command according to your need. You can change your name, description, and vpc id.

Create security group rules

we want to add rules to the security group that we have created above.

If you copy-paste the security group id then skip the below command...

Let's find the security group name and id.

the above command will give you a list of security group names and ids.

copy the id that we want to add a new rule and paste it in the below command.

the above command will create a new rule for ssh.. you can always customize as per your need... you know that right?

You can check more examples of multiple rules here...

Check that rule added successfully or not using describe subcommand.

Create a new instance

You may want to launch an instance in a specific availability zone. let’s see with AZ are available in the region you specified while configuring.

We want to attach one more EBSvolume to our instance and for that, both should in the same availability zone. Fix your availability zone for that.

AWS CLI has very well described documentation for ec2.. let's take the help of that. It will give more examples and necessary information. You always need something different than I used here.. so go and use

$ aws ec2 help

To launch an instance we need ami id of the image that we want to launch..

$ aws ec2 describe-images

I have used the key pair and security group that we have created above. I choose the ap-south-1a availability zone and amazon Linux ami to launch this instance.

You can do much more customization to this command. Check this aws Documentation.(open)

copy instance id and save it somewhere.. we will see later where we need.