How AWS CLI helps in managing AWS account 🧐 🧐 🧐

Hola guys ! πŸ–

I hope you all are well. So, guys again i am with you with my blog, I hope you like this. 🀩 🀩 🀩

Today we will learn :

🀯 How to create Key-pairs using aws CLI

🀯 How to create Security- Group using aws CLI

🀯 How to create a EC2 instance, stop, start EC2 instance using aws CLI

🀯 How to create EBS volume using aws CLI

🀯 How to connect EBS volume with instance using aws CLI

and so on.

So, Let’s start 🀠 😎

We already setup and configured our aws cli in my last article. So, now we start directly with above mentioned topic.

If you’re not gone through my last blog β€œ How to Setup and Configure AWS CLI” , then first go through πŸ“‘ that to better understand AWS CLI .

blog : πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡

How to create Key-Pair using AWS CLI οΏ½πŸ€”οΏ½πŸ€”οΏ½

To create Key pair we have to first explore AWS CLI with help command. As we know key-pair are for EC2, it must be in aws EC2. so, to create the key-pair we will use β€œ aws ec2 create-key-pair β€œ command.

But before we have to explore it using β€œ aws ec2 create-key-pair help β€œ command.

OUTPUT :

aws ec2 creeate-key pair help
aws ec2 creeate-key pair help

So, from above output we get all parameters also. so now we can easily create key-pair by using command :

Command:

aws ec2 create-key-pair β€” key-name MyKeyPair

Before command (aws webUI screenshot) : 🀞 🀞 🀞

Before Creating Keypair

NOw I run command :

aws ec2 create-key-pair β€” key-name KushTaskPair

CLI command to create Key-pair & output

After Command ( aws webUI Screenshot) : 😍😍😍

Key-pair Created

Hence, we have successfully created our key-pairs. 🀟 🀟 🀟

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

Now, we move ahead and create Security Group. πŸ‘£πŸ‘£πŸ‘£

How to create Security- Group using AWS CLI οΏ½πŸ€”οΏ½πŸ€”οΏ½

Now to create Security- Group again we have to first explore AWS CLI commands with help command. As we know Security- Group are for EC2, it must be in aws EC2 field. so, to create the security-pair we will use β€œ aws ec2 create-security-group β€œ command.

But before we have to explore it using β€œ aws ec2 create-security-group help β€œ command.

OUTPUT :

aws ec2 create-security-group help
aws ec2 create-security-group help

So, from above output we get all parameters also. so now we can easily create Security-Pair by using command :

Command:

aws ec2 create-security-group β€” group-name MySecurityGroup β€” description β€œMy security group”

Before command (aws webUI screenshot) : 🀞 🀞 🀞

Before Security Group Creation

Now I run command :

aws ec2 create-security-group β€” group-name KushSG β€” description β€œKush security group”

OUTPUT :

Command OUTPUT

After Command ( aws webUI Screenshot) : 😍😍😍

After Command

Hence, we have successfully created our Security-group. 🀟 🀟 🀟

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

Now, we move ahead and create ec2 instance.πŸ‘£πŸ‘£πŸ‘£

How to create a EC2 instance, stop, start EC2 instance using aws CLI οΏ½πŸ€”οΏ½πŸ€”οΏ½

Now to create Ec2 instance, so again we have to first explore AWS CLI commands with help command. so, to create the instance we will use β€œ aws ec2 run-instancesβ€œ command.

But before we have to explore it using β€œ aws ec2 run-instances help β€œ command.

From the above command we get all ec2 run-instance command parameters. So now we can easily run instance by using command :

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 command (aws webUI screenshot) : 🀞 🀞 🀞

Before Security Group Creation

Now I run command :

aws ec2 run-instances

β€” image-id ami-0e306788ff2473ccb

β€” count 1 β€” instance-type t2.micro

β€” key-name KushKeyPair

β€” subnet-id subnet-3bb8bd53

β€” key-name KushKeyPair

β€” security-group-ids sg-011edc57ff90b75bc

OUTPUT :

After Command ( aws webUI Screenshot) : 😍😍😍

Hence, we have successfully created our Instance. 🀟 🀟 🀟 hurrey!!!!!

NOTE: We can also do following using aes Cli :

✍🏻 Stop Instance by β€œ aws ec2 stop-instances Instance-ID”

✍🏻 Start Stopped Instance by β€œ aws ec2 start-instances Instance-ID”

✍🏻 Terminate Instance by β€œ aws ec2 terminate-instance Instance-ID”

✍🏻 List Instances by β€œaws ec2 describe-instances”

Now, we move ahead and create a EBS storage of 1Gib.πŸ‘£πŸ‘£πŸ‘£

How to create EBS volume using aws CLI οΏ½πŸ€”οΏ½πŸ€”οΏ½

Now to create EBS storage, so again we have to first explore AWS CLI commands with help command. As we know EBS are sub-service of EC2, so it must be in aws EC2 field. so, to create the EBS volume we will use β€œ aws ec2 create-volume β€œ command.

But before we have to explore it using β€œ aws ec2 create-volume help β€œ command.

OUTPUT :

aws ec2 create-volume help
aws ec2 create-volume help

So, from above output we get all parameters also. so now we can easily create EBS volume by using command :

Command:

aws ec2 create-volume \
β€” volume-type gp2 \
β€” size 80 \
β€” availability-zone us-east-1a

Before command (aws webUI screenshot) : 🀞 🀞 🀞

Before Command

Now I run command :

aws ec2 create-volume \
β€” volume-type gp2 \
β€” size 1\
β€” availability-zone ap-south-1a

OUTPUT :

aws ec2 create-volume command

After Command ( aws webUI Screenshot) : 😍😍😍

Hence, we have successfully created our EBS volume. 🀟 🀟 🀟

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

Now, we move ahead and attach volume with ec2 instance.πŸ‘£πŸ‘£πŸ‘£

How to connect EBS volume with instance using aws CLI 🀯 🀯 🀯

So, now we attach our EBS volume with aws instance. So for this we will use following command.

Command :

aws ec2 attach-volume

β€” volume-id vol-ID

β€” instance-id i-ID

β€” device /dev/sdf

Before command (aws webUI screenshot) : 🀞 🀞 🀞

Now I run command :

aws ec2 attach-volume β€” volume-id vol-0d5c8d0cd9ab3cec0 β€” instance-id i-0a6281bfccee7dba5 β€” device /dev/sdf

OUTPUT :

After Command ( aws webUI Screenshot) : 😍😍😍

Hence, we have successfully attached our EBS volume. 🀟 🀟 🀟

So, guys by this we come to end of my article .

In last I conclude that :

  1. AWS CLI is better and very fast than AWS webUI.
  2. Once we come to about basic commands of CLI, we can easily operate AWS services.
  3. All service follows following procedure :

πŸ‘‰ Find command from help menu of particular command.

πŸ‘‰ Then find parameters by again aws subcommand help.

πŸ‘‰ Then as per example and requirement use the services.

Thats all guys !

If you like my blog and wants such blog follow me on medium.

In upcoming days I am going to publish lots of articles on Cloud Computing Technologies and many case-study, So definitely follow me on Medium.

Here is my LinkedIn profile link and if you have any queries definitely Comment.

YouTuber || Instructor & Teacher || Technical Content Writer || MLOps || DevOps || Hybrid Multi Cloud || Flutter || Python || Arth Learner || Technology Lover