How to Create a Key Pair, Security Group, Launch an Instance & Create an EBS volume Using AWS CLI

Aniket kashyap
AWS in Plain English
3 min readMay 31, 2021

--

AWS CLI (Command Line Interface)→ It is a unified tool used to manage AWS services. Even the graphical portal of AWS can’t do like launching multiple instances of a different type in a single go can be done through AWS CLI. We can control multiple services of AWS from the command line and automate them through the script.

Before digging in, let’s take a look at the topics covered in this article.

🔅 Download and configure the AWS CLI.

🔅 how to create of IAM user for Credentials.

🔅 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

Download and configure the AWS CLI and create an IAM user for Credentials for this you can refer to this article

https://aws.plainenglish.io/how-to-install-setup-and-execute-aws-cli-command-line-interface-on-windows-80838e0d898a

Create a key pair

keypair → A key pair, consisting of private and public keys is a set of security credentials that you use to prove your identity when connecting to an instance. If you plan to connect to instances using SSH, you must specify a key pair

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

Create a security group

> aws ec2 create-security-group --description “aws cli security group” --group-name <security group name >

Launch an instance using the above created key pair and security group.

> aws ec2 run-instances --image-id <imade id >--instance-type t2.micro --count 1 --subnet-id <subnet id>--security-group-ids <security group id> --key-name <key pair name >

Create an EBS volume of 1 GB.

aws ec2 create-volume --volume-type gp2 --size 1 --availability-zone ap-south-1a

Attach EBS volume to the instance we created above

Here we will give the instance id and volume id that we created above.

aws ec2 attach-volume --volume-id <volume id> --instance-id <instance id> --device /dev/sdf

Congrats for completing all the tasks…

Thanks for reading this article, and please leave a note with any suggestions for improvements. Feel free to connect with me, either here or on LinkedIn:

More content at plainenglish.io

--

--