Using AWS console via AWS CLI
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:
- 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.
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” .
Now use command “aws ec2 create-key-pair — key-name MyKeyPair”
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” .
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”
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
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\
— 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.
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
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.