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 :
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) : π€ π€ π€
NOw I run command :
aws ec2 create-key-pair β key-name KushTaskPair
After Command ( aws webUI Screenshot) : πππ
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 :
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) : π€ π€ π€
Now I run command :
aws ec2 create-security-group β group-name KushSG β description βKush security groupβ
OUTPUT :
After Command ( aws webUI Screenshot) : πππ
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) : π€ π€ π€
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 :
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) : π€ π€ π€
Now I run command :
aws ec2 create-volume \
β volume-type gp2 \
β size 1\
β availability-zone ap-south-1a
OUTPUT :
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 :
- AWS CLI is better and very fast than AWS webUI.
- Once we come to about basic commands of CLI, we can easily operate AWS services.
- 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.