Nikhil S Wani
4 min readMar 28, 2021

--

Objective:-

  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 GB.
  5. The final step is to attach the above created EBS volume to the instance you created in the previous steps.

6. Stop the instance.

7. Terminate the instance.

Open cmd in windows. run ‘aws’ command and check whether AWS-CLI is installed or not.

Note:-If you haven't install AWS-CLI, Plz read my previous blog.

1. Create a key pair

Essential things to create a key is the key name and this service is under the ec2 service.

Execute the following command.

aws ec2 create-key-pair — key-name nikhilKey

2. Create a security group

Essential thins for security group are security group name, and in which PVC we have to create a security group and the optional thing is a description.

Execute the following command.

aws ec2 create-security-group — group-name “cli_grp” — description “SG Created by CLI” — vpc-id vpc-fb5ea790

How to get VPC id??

Follow this path.

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

Essential things to launce instance are

  1. Which Image do you want to launch?
  2. Which type of instance do you want to launch?
  3. Which key you have to use?
  4. In which subnet you want to launch the instance?
  5. How many instances do you want to launch?

aws ec2 run-instance — image-id ami-068d43a544160b7ef — instance-type t2.micro — key-name nikhilKey — subnet-id subnet-7b08ee10 — count 1

How to get an image id?

How to get instance type?

How to get a subnet id?

4. Create an EBS volume of 1 GB.

Required things are volume type and in which availability zone you want to launch volume.

execute the following command.

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

How to get an availability zone?

5. The final step is to attach the above created EBS volume to the instance you created in the previous steps.

The required things are

  1. Volume id to be attached.
  2. Instance id.
  3. device name.

Execute the following command

aws ec2 attach-volume — volume-id vol0c529723c45af2917 — instance-id i-08bfge5a955c6b6f — device /dev/sdf

6. Stop the instance.

The required thing is instance id.

Execute the following command

aws ec2 stop-instances — instance-id i-08bfge5a955c6b6f

7. Terminate the instance.

Execute the following command.

aws ec2 terminate-instances — instance-id i-08bfge5a955c6b6f

Hope this blog will be helpful.

Thanks for reading ……

--

--