AWS CLI

Rohit Raut
5 min readOct 13, 2020

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.

If you decide to use Amazon AWS cloud for your project then the first thing you need is to install Amazon CLI (Command Line Interface) to start automating your basic Amazon AWS operations or you can go for terraform.

AWS CLI provides command and we can use this commands to automate them through scripts.

Let’s create Infrastructure using CLI:

⭐Create a key pair

⭐Create a security group and add a rule with port 22 [SSH]

⭐Launch an instance using the above created key pair and security group.

⭐Create an EBS volume of 1 GB.

⭐ Attach the above created EBS volume to the instance you created in the previous steps.

Let’s get started with Setup

Step 1: Setup Amazon AWS CLI:

Here, make sure you have selected Programmatic access because it gives you an access key and a secret key required to work with CLI.

Set Permission

Here we have to give the administrator Access so in the future we won’t face any access issue. Except for billing Dashboard, we have access to all services with administrator access power.

Download Amazon AWS Access Key and Secret Access Key

Go To: https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html, download and install the AWS CLI Program.

How to check if Amazon CLI is installed successfully?

that’s it we have successfully installed AWS CLI Version 2

Configure AWS CLI

just type aws configure and give the access key and the secret access key which we have download after creating IAM user.

Here, we have successfully done with the configuration.

Let’s get started with Infrastructure

step 1: Create a key pair

We need to generate a keypair because when we launch an instance it needs a key. The Key is used by the local machine login to the instance so that we can perform our task there.

we have to save with special format as we can see this key material come with

NewLine(\n)

for this, we need to process this key.

Step 2: Create a security group and add a rule with port 22 [SSH]

A security group acts as a virtual firewall for your instance to control inbound and outbound traffic. When you launch an instance in a VPC, you can assign up to five security groups to the instance. Security groups act at the instance level, not the subnet level. Therefore, each instance in a subnet in your VPC can be assigned to a different set of security groups.

You can check/verify the security group from the command line and also from Web-UI

Check From CLI, this command list out all security group.

aws ec2 describe-security-groups

WebUI:

When we create a security group from CLI, it comes with empty inbound traffic rules.

To add rule

aws ec2 authorize-security-group-ingress --group-name CLI --protocol tcp --port 22 --cidr 0.0.0.0/0

Step3: Launch an instance using the above created key pair and security group.

Amazon Elastic Compute Cloud (EC2) is a part of Amazon.com’s cloud-computing platform, Amazon Web Services (AWS), that allows users to rent virtual computers on which to run their own computer applications.

aws ec2 run-instances --image-id ami-0e306788ff2473ccb --instance-type t2.micro --key-name Hadoop --security-group-ids sg-0d1d5e82788ce8dbc --subnet-id subnet-c0646da8 --count 1

Step4: Create an EBS volume of 1 GB.

An Amazon EBS volume is a durable, block-level storage device that you can attach to your instances. After you attach a volume to an instance, you can use it as you would use a physical hard drive. EBS volumes are flexible.

Volume

Step 5: Attach the above created EBS volume to the instance created in the previous steps.

Instance Description.

now, we can connect to the instance using SSH as we have already updated the security group with port 22.

completed with the TASK.

THANK YOU FOR READING!!😀😇

--

--