Getting started with AWS CLI ( Command Line Interface )

Megha Bansal
Analytics Vidhya
Published in
4 min readOct 13, 2020

WHAT IS CLI?

CLI is a command-line program that accepts text input to execute functions. AWS provides us with an option of accessing their tools using AWS CLI. With minimal configuration, the AWS CLI enables you to start running commands that implement functionality equivalent to that provided by the browser-based AWS Management Console from the command prompt in your terminal program

WHY AWS CLI?

Saves Time- Suppose you are trying to find a large folder. You have to log in to your account, find the right folder and look for the right file. But with AWS CLI, if you know the right command the entire tasks will take just a few seconds

Automation- It gives you the ability to automate the entire process of controlling and managing AWS services through scripts. There are many things which the web UI can’t automate, everything is very manual. For eg- We can’t launch 2 EC2 instances from different AMI at one click.

INSTALLING AND CONFIGURING AWS CLI

You can install the CLI from here according to your Operating System.

→After installing, you have to configure it. It includes your security credentials, the default output format, and the default AWS Region. For this, you’ll require the Access Key ID and Secret Access Key which can be obtained by IAM after creating a user / existing user with appropriate policies ( I have attached PowerUserAccess ). After creating a user, you’ll get the credentials.

Access Key ID and Secret Access Key

→ Go to your CMD and type

aws configure

→ Enter the Access key ID, Secret Acess Key, Region and the Output Format (default is JSON) for your commands.

You’re done with the setup!

PRACTICAL

This practical consists of the following tasks:

🔅 Create a key pair

🔅 Create a security group

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

🔅 Create an EBS volume of 1 GB.

🔅 The final step is to attach the above created EBS volume to the instance created in the previous steps

1. Create a key pair

aws ec2 create-key-pair --key-name myclikey
CLI
AWS Management Console

2. Create a security group

aws ec2 create-security-group --group-name aws_cli_intro --description "aws cli" --vpc-id vpc-2ef81845
CLI
AWS Management Console

Adding ingress rules to a security group:

aws ec2 authorize-security-group-ingress -- group-id sg-02915ad4c4814ecda --group-name aws_cli_intro --protocol tcp --port 22 --cidr 0.0.0.0/0
Rule Created in AWS Console

3. Launch an ec2 instance

aws ec2 run-instances --image-id ami-0e306788ff2473ccb --instance-type t2.micro --count=1 --subnet-id subnet-1ce09f50 --security-group-ids sg-02915ad4c4814ecda --key-name myclikey
CLI
AWS Management Console

4. Create an EBS volume of 1 GB

aws ec2 create-volume --availability-zone ap-south-1b --size 1
AWS Management Console

5. Attach the volume to the instance

aws ec2 attach-volume --volume-id vol-09866940fb6a5eb52 --instance-id i-07c80aac43edf812f --device=/dev/sdf
CLI
Volume attached

Now we can do remote login using

ssh -l ec2-user <public IP> -i myclikey.pem
Connect to the instance using SSH

And further, create partition and store data

→Create partition:

→ Format partition:

→ Mount Partition:

You’re good to go!

Thank you! Hope you had a wonderful read

In case of any query, reach out to me on Linkedln.

--

--

Megha Bansal
Analytics Vidhya

DevOps Engineer at JFrog | Linux | Python | Git | Docker | Kubernetes | AWS | Terraform | CI-CD