So in the task given we have to

🔅 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.

All the above tasks have to be done using AWS CLI.

Lets start doing it:😁

✅First we have to create an IAM user

IAM stands for Identity Access Management. IAM allows you to manage users and their level of access to the aws console.

✔We have to give a user name and programmatic access as the access type so that it enables access to access key and secret key in aws cli.

✔We have to set certain permissions for the user. So here we can give them access to many services and i have chosen AmazonEC2FullAccess and Power Access.

✔We can add tags if we want to .

✔Aws will generate access key and secret key for the user created aws1 which should be used later to login to our aws cli.

😸Now aws1 user is created.

✅Now we use AWS CLI to perform the above mentioned tasks.

✔In windows command prompt we use the command “ aws configure” to login into our user account where we can login using the access key and secret access key.

✔Now we have to create a key pair. Since there are many commands related to a single service we can take the help of “help” command which shows the various commands that can be used .

aws <command> help

We are using ec2 command :aws ec2 help

Here we can see the description of ec2 service and the available commands that can be used.

✔We can see a command called “create-key-pair” which can be used for our task .

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

We have created the keypair and we have given the key name as “KeyName”.

✅Now we have to create our own security group. Once again we can take the help of “aws ec2 help” command to know about the command we have to use to create security group.

✔We can create our own security group using the command:

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

✅With the help of the key pair and the security group created we can launch an new instance using the command:

✔The command used is :

aws run-instances — image-id <image_id>— instance-type<type> — subnet-id <subnet_id>— count <count>— security-group-ids <group_id>— key-name <key_name_we_created>

So now we have launched a new instance 😸😸

We can see that the instance is launched even in the AWS WEBUI.

✅Our next task is to create a EBS volume of 1GB.

EBS stands for Elastic Block storage. It is a highly available, durable persistent block level storage service provided for use with Amazon EC2 instances in the AWS Cloud.

✔So to create our own volume of 1GB we use the command:

aws ec2 create-volume — volume-type <volume_type>— size <size>— availability-zone <zone>

We have successfully created EBS volume of 1GB.😸😸

We can see this is in GUI(webui) also

✅Hurrah!!We have reached the final step where we have to attach the EBS volume we created to the instance we created in the previous steps.

✔For this we use the command:

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

We can see that the volume is attached to the instance in both Cli and Gui

✅Now we can stop the instance using the command:

aws ec2 stop-instances — instance-id <id>

Here the instance-id is i-0dd7b6752bdea9218

😸So we successfully created an instance with an attached volume of 1GB using the AWS CLI.😸

NOTE: You can use “aws <command> help” to see the other commands that can be helpful for your tasks.

🎯I hope you find this article useful and helpful!!

Thanks for reading!!🎯