How to launch an Instance and create a SG, Key- Pair & Volume in AWS using CLI ?

In this article, you come to know how to launch an instance and how to create a volume, security-group & key-pair as well as how to attach an EBS volume to the instance using CLI.

What is AWS ?

Amazon Web Services (AWS) is a subsidiary of Amazon providing on-demand cloud computing platforms and APIs to individuals, companies, and governments, on a metered pay-as-you-go basis. These cloud computing web services provide a variety of basic abstract technical infrastructure and distributed computing building blocks and tools.

Now, the question comes why we are using CLI in place of GUI. So, following are the benefits of CLI over GUI:-

  • Whether you are writing a code or giving instructions to the computer CLI gives better control to the user.

Task Description:-

  1. Create a key-pair

So, let’s get started …

Step 1:- Create a key -pair. We can use the following command to create a key-pair:-

Here, I had given my key-pair name as MyTaskKey. You can give any name according to your choice.

Note:- Always save the key i.e., output of this command . You will need this key when you will login in the instance.

So, we have create a key-pair named as MyTaskKey.

Step 2:- Next, we have to create a security-group. Following is the command for the same:-

Our security- group is also ready. You can see it in the below image.

Step 3:- Now, we have to launch an instance using above created security-group and key-pair.The command for the same is as follows:-

Here, I used ami-0a9d27a9f4f5c0ef image-id, t2.micro instance-type. You can use according to your requirement.

So, our instance is also ready.

Step 4:- Next, we have to create an EBS volume of 1 GB. The command for the same is as follows:-

Note:- The availability-zone of the instance and EBS volme sholud be same otherwise we can’t attach the EBS volume to the instane as EBS volume is available on region basis.

Step 5:- Now, we have to attach the above created EBS volume to the instance we created in Step 3. The command for the same is as follows:-

Finally, we have attached EBS volume to the instance.

Thanks for reading :)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store