Creating Key Pair, Security Group , EBS Volume and Attach them to AWS Instance using AWS-CLI?

Yagyandatta Murmu
4 min readOct 17, 2020

What is AWS CLI ?

The AWS Command Line Interface (CLI) is a unified tool to manage your AWS services. With just one tool to download and configure, you can control multiple AWS services from the command line and automate them through scripts.

Why AWS CLI ?

Automation leads to faster processing of voluminous tasks and reduced turnaround timelines. A reduction in enterprise costs and the time involved in executing operational activities leads to improved workflow efficiencies. AWS CLI allowing you to control and configure multiple AWS services and implement a level of automation.

How to Install AWS CLI ?

The AWS Command Line Interface can be installed on Windows by using a standalone installer. You have to download and install.

Download the appropriate MSI installer.

For Windows (64bit) :-   click me

CONFIGURATION :

  • To verify the installation use this command:-

aws — -version

aws-cli version

To Configure AWS :-

Now the challenge is that, AWS CLI can’t work with our root account of AWS. It only work with IAM user , where you have to provide the access key ID (user-ID) and secret key (password) of user to the CLI for AWS-CLI log-in. You can generate new credentials within AWS Identity and Access Management (IAM) if you do not already have them. The other information you will need is region and output format, which you can leave as default for the time being.

Task Description — AWS
1.Create a key pair
2.Create a security group
3.Launch an instance using the above created key pair and security group.
4.Create an EBS volume of 1 GiB.
5.Attach the above created EBS volume to the instance you created.

1. Creating the key pair

You can get help with any command when using the AWS Command Line Interface (AWS CLI). To do so, simply type help at the end of a command name.

aws help
help in AWS

The help includes descriptions of its input parameters, available filters, and what is included as output. It also includes examples showing how to type common variations of the command. By usinghelp command we got the code to create a key pair in AWS-CLI.

aws ec2 create-key-pair --key-name <value>

Key Has Been Created :

cli
webUI

2. Creating a security group:-

aws ec2 create-security-group --description <value> --group-name <value>

3. Launching the instance using the above created key pair and security group.

we have to collect the below data to launch an instance.

aws ec2 run-instances   //to launch
--image-id // to launch we need os-image
--instance-type // os type --count 1
--subnet-id //server zone id
--security-group-ids //security rule group id
--key-name // keyName for authentication
in cli

we can see same result in webUI for proof.

webUI

4.Creating an EBS volume of 1 GiB.

aws ec2 create-volume  --availability-zone <value> --size <value>

5.Attach the above created EBS volume to the instance you created.

aws ec2 attach-volume --device <value> --instance-id <value>  --volume-id <value>
webUI

Thank You for reading…

--

--

Yagyandatta Murmu

Devops || MlOps || Flutter || Web Development || PYTHON || Data Science || AWS cloud || GCP || Azure