Managing AWS Console From Command Line Interface(CLI)

Abhishek Dwibedy
6 min readOct 16, 2020

In this we shall come across how can we use AWS services in Command line interface(CLI) . As in GUI(Graphical User Interface) there is lots of option available and we have to choose again and again and again, and you know in 21st century nobody (specially Developers)want to waste their time. So using CLI we can do every instruction and most of the practical in a single go.

Task Description — AWS 👨🏻‍💻

🔅 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 you created in the previous steps.

All the above steps are being performed using AWS CLI .

To perform all the above process we have to first install The AWS CLI software .

  1. Search on Google- “AWS CLI install” then click on that link.

2. Now click on this below link to download the software.

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

3. The installation is quite simple . By double click we can simply install the software. We can check in windows command prompt whether it is installed or not by typing the command - aws — version .

For Access to AWS CLI

Before moving into CLI we must have an AWS account created and after that we will create a IAM user for an Authentication & get the Access Key and Secret Key.

New IAM User Is being created

After Successful creation of IAM user now lets move to our CLI where we can authenticate to our AWS account using the IAM user that we created by providing the Access key, Secret key & Region, using the command -# aws configure.

We have Configured successfully.

🔅 Now let’s see how to create a key pair :

Before creating a new keypair let’s check how many keypair i have in my AWS Account in GUI.

As we can see there is only one key pair present in my account which I had done before using the GUI interface .Now let’s create a new keypair by using CLI and see a new keypair is being created or not.

By “help” command we can find our approach that what we have required to do after that.

A new key-pair awscli is being created.

Command — aws ec2 create-key-pair — key-name <value>

aws ec2 create-key-pair — key-name awscli is the command through which a new keypair is being created for us.

Now let’s check in GUI whether a new key pair named awscli is being created or not.

We can see that a new key pair named awscli is being added to the list that we have been created through CLI.

🔅 Creating a Security group : Command

A security group is something similar to a gate which acts as a virtual firewall for our instances to control inbound and outbound traffic.

Command :- #aws ec2 create-security-group — group-name <value> — description <value>

Before running this command I had this much security group in my AWS account .

Now , create a new security group “awsclisg” using the above command in CLI and let’s see it being created or not.

aws ec2 create-security-group --description "awsclisg"  --group-name arth

It’s being created in CLI .Let’s go and check in GUI whether it is created or not.

A new security group is being created after we run the command.
Sequrity group Description

For describing Security groups Command is :- aws ec2 describe-security-groups --group-ids sg-059631cb4e59da829

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

To launch new instances in CLI the command is : aws ec2 run-instances — image-id <value> — instance-type <value> — count 1 — subnet-id subnet <value> — security-group-ids <value> — key-name <value>

We have launched a new instances using the above key and the security group id that we have been created the command is -

aws ec2 run-instances --image-id ami-0e306788ff2473ccb --security-group-ids sg-059631cb4e59da829 --instance-type t2.micro --key-name awscli --count 1

As we can see a new instances has been created and is being successful running.

We can also check from CLI whether it is running or not by using the command :-

aws ec2 describe-instances --instance-ids i-04768b9bd6999634f
It is successfully running.

🔅 Now we create an EBS volume of 1 GB :

To create an EBS Volume the command is : aws ec2 create-volume — volume-type <value> — size <value> — availability-zone <value>

We have created a EBS Volume of 1 GB successfully.

Command is -

aws ec2 create-volume — availability-zone ap-south-1a — volume-type gp2 — size 1

In AWS console page we checked that a 1 Gb volume is being created for us.

🔅 To attach the above created 1 GB of EBS volume to the AWS Ec2 Instance :-

For attach the ebs volume the command is : aws ec2 attach-volume — instance-id <value> — volume-id <value> — device <value>

EBS volume is attached

Command-aws ec2 attach-volume — instance-id i-04768b9bd6999634f — volume-id vol-04ba9d6505c34c08f — device /dev/xvda

Successfully Attached.
EBS Detached

The EBS Volume of 1GB is being attatched to the instances.

After attatching we can also detach the EBS by the command aws ec2 detach-volume — instance-id i-04768b9bd6999634f — volume-id vol-04ba9d6505c34c08f — device dev/xvdf

EBS Volume is detached successfully.

And here our requirement is finished up So I’m stopping my instance from AWS CLI, So To stop the instances the command for it is -aws ec2 stop-instances — instance-id i-04768b9bd6999634f

Our instance is successfully stopped.

Let’s check on AWS CONSOLE should we successfully done all the above things ?? Ya!!! The instance has successfully stopped.

!! HAPPY LEARNING !!

--

--