Using AWS console via AWS CLI

Sanchita Agrawal
5 min readMay 29, 2021

--

Hello guys😊

I’ve come up with a new blog on AWS CLI i.e. how to manage aws console by cli.

what we will learn:

  1. Create a key pair
  2. Create a security group
  3. Launch an instance using the above
    created key pair and security group.
  4. Create an EBS volume of 1 GB.
  5. The final step is to attach the
    above created EBS volume to the
    instance you created in the previous steps.

Create Key Pair

It’s not necessary to learn all the commands to work on aws cli. Its human tendency we forget somethings. So, even if you forget you don’t need to panic. Just always remember the basic commands and if you can’t remember it just remember “aws help” .

To create key pair using aws cli we must explore aws with its “aws help” command . Key Pair must be in Ec2 instance so we give command “aws ec2 create-key-pair”. We must explore this by help command “aws ec2 create-key-pair help” .

aws ec2 help
aws ec2 create-key-pair help

Now use command “aws ec2 create-key-pair — key-name MyKeyPair”

Before command “aws ec2 create-key-pair — key-name MyKeyPair”
creating keypair with command “aws ec2 create-key-pair — key-name testkeypair”
after running command “testkeypair” added

NOTE : We can delete security group using “ aws ec2 delete-key-pair” command using same approach.

Create a Security Group

To create security group using aws cli we must explore aws with its “aws help” command . Security Group must be in Ec2 instance so we give command “aws ec2 create-security-group”. We must explore this by help command “aws ec2 create-security-group help” .

command “aws ec2 create-security-group help”

Now use command aws ec2 create-security-group — group-name MySecurityGroup — description “My security group”

Before command aws ec2 create-security-group — group-name MySecurityGroup — description “My security group”

Run the command
After running the command

NOTE: We can delete security group using “ aws ec2 delete-security-group” command using same approach.

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

To launch instance using aws cli we must explore aws with its “aws help” command . Instance must be launched in Ec2service of aws so we give command “aws ec2 run-instances”. We must explore this by help command “aws ec2 run-instances help” .

command “aws ec2 run-instances help”

Command:

aws ec2 run-instances \
— image-id ami-ID\
— count 1 \
— instance-type t2.micro \
— key-name MyKeyPair \
— security-group-ids sg-ID\
— subnet-id subnet-ID

Before running the command
command run
After running command one instance is launched in aws WebUI

NOTE: We can also do following using AWS CLI :

Stop Instance by “ aws ec2 stop-instances Instance-ID” Stop Instance by “ aws ec2 stop-instances Instance-ID”

Start Stopped Instance by “ aws ec2 start-instances Instance-ID” Start Stopped Instance by “ aws ec2 start-instances Instance-ID”

Terminate Instance by “ aws ec2 terminate-instance Instance-ID” Terminate Instance by “ aws ec2 terminate-instance Instance-ID”

List Instances by “aws ec2 describe-instances” List Instances by “aws ec2 describe-instances”

Create an EBS volume of 1 GB

EBS storage of 1 GB must be launched and attach in the Ec2 instance of aws so we give command “aws ec2 create-volume”. We must explore this by help command “aws ec2 create-volume help” .

command “aws ec2 create-volume help”

Command:

aws ec2 create-volume\

— volume-type gp2 \

— size 1\

— availability-zone ap-south-1b\

Note: Always create EBS volume in the same availability zone where you’ve launched your instances.

Before running command
running command
After running the command

Now, We have launched EBS volume.

NOTE: We can delete security group using “ aws ec2 delete-volume” command using same approach.

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

To attach above EBS volume to our above created instance we use command

Command :

aws ec2 attach-volume

— volume-id vol-ID

— instance-id i-ID

— device /dev/sdf

Before only one single storage is attached
Run the command
Now the EBS storage is added

Now the EBS storage we created earlier is attached to our created instance.

So, guys this is how we use aws console via AWS CLI with basic commands.

Thankyou !!

Stay Connected for more tech blogs.

--

--

Sanchita Agrawal
Sanchita Agrawal

Written by Sanchita Agrawal

0 Followers

Computer Science Major || Software Developer@GenusPower

No responses yet