AWS
How we can use services of AWS cloud using Command Line Interface or AWS CLI(black screen)
Hello Connections ..!!
Hope you are doing well✌, today I am going to perform a simple task of launching a new instance on AWS Cloud using AWS CLI(black screen)and here I am trying my best to make understand this in a very simple and comfortable language .Hope you will enjoy it ,let's do:
👉 Task Description💻
- Creating a New Key Pair.
- Creating a Security Group.
- Creating New Inbound Rules.
- Launch an instance using above Key pair & Security group.
- Create an EBS Volume & Attach it to the launched Instance.
- Detaching the EBS volume & finally Terminate the instance.
🖋Firstly we should have to know what is actually a AWS CLI,so :-
😇 What is AWS CLI?
It is basically a way like CMD for operating on the windows by using some commands so we can say AWS CLI is the tool that pulls all the AWS services together in one central console or we can in only one command, giving you easy control of multiple AWS services with a single tool. The major advantage of CLI over GUI is that we can use multiples services of AWS in one time , so it a very timing saving tool, hope you will understand what I am trying to say here. If there is any conflict in this feel free to ask...😎.
Pre-Requisite :-
You should have AWS CLI software installed in your system. There is two versions of CLI i.e version 1 and version2 and I recommend to you all to use version2 because it is upgraded version
For downloading this software click_here.
Now you are ready to perform on black screen, go in CMD and type AWS then press enter.
- Now terminal is opened(black screen) of AWS in this, check whether AWS is working or not type AWS in cmd the below screen will come..
wow! it's working ..😀 it is not the error, this black screen want the any to logged in into cloud as IAM user using the command "aws configure" then it will ask you for an access key and security key now provide these key and press, if there is no error ,you finally logged in ...as shown in image given below .So, finally you done all your setup for preforming your task😊😊
- How to create a New Key Pair?
Use command : aws ec2 create-key-pair --key-name <key value>
Here key value is the name of the key and it is user defined.
The image given below give you the complete how actually it is worked...
Here, key is created you can see "shubham_key" is the key name
In the command may you guys think what is ec2 here? ec2 is one of the services provides by aws cloud to launches or installing the operating system while we launching we need the key for authentication purposes. So , I hope you will get my point ,if you have any doubts ,feel free to ask 🤗
How to create your own security group?
Use command:-aws ec2 create-security-group --group-name <any_name> --description <description_name>
Here ,I give "har_security" as a group name and description also.
- How to create your own security rules or we can say how we control the inbound traffic
Use command : aws ec2 authorize-security-group-ingress --group-id sg-09a7299068a2f6486 --group-name har_security --protocol tcp --port 22 --cidr 0.0.0.0/0
So, we here we have created our own security group rules, notice one point here, I am using cidr is 0.0.0.0/0 it means that anyone can connect to our instance any one there is no any restrictions ,Anyone can come and go connect, this is the rule we create here😊
- How to launch a new instance using above key-pair & security group?
Use the command:-aws ec2 run-instances --image-id ami-0e306788ff2473cc --instance-type t2.micro --key-name shubham_key --security-group-ids sg-09a7299068a2f6486 --subnet-id subnet-833f36eb --count 1
Here you can see when I run the command then the instance is created and you can check the ids on AWS CLI and on GUI of aws cloud ,they will be same as shown in figure and the instance created is in running condition.. 😃😃
- How to create EBS volume and attach it to the launched instance?
First we have to create the volume, use command given below:-
aws ec2 create-volume --volume-type gp2 --size 1 --availability-zone ap-south-1a
As you can see in image the volume is created.
Now, we have to attach this volume to the particular instances
Use command:-aws ec2 attach-volume --instance-id i-050c438eedc66533d --volume-id vol-01c96850d7a055240 --device /dev/xvdf
In figure ,we can see that the volume which we created is attached to the particular instance😀
So , guys finally completed the task.. now one thing left we should have to detach the volume before terminating the instance
- To detach the volume
- Use command:-aws ec2 detach-volume --instance-id i-050c438eedc66533d --device /dev/xvdf --volume-id vol-01c96850d7a055240 --force
So here we can see , in the attachment information there empty box.. that mean our volume is detached from the instance.
- How to terminate the instance?
Use command:-aws ec2 terminate-instances --instance-ids i-050c438eedc66533d
In this image above we have seen that our instance is terminated..☺😊
That's sound is great our task now completed successfully🥰🥰
I would like to thanks to Mr. Vimal Daga Sir for giving this challenging task .While doing this task ,I learnt a lot of things related to AWS CLI
If you have any problem in this task then feel free to ask , i will do my best to make you understand
Thankyou all of you.
#vimaldaga #awscli #aws #righteducation #rightmentor #uttaranchaluniversity
#linuxworld #makingindiafutureready
@Vimal Daga @Preeti @Onkar Naik