Accessing AWS Elastic Block Storage from CLI

Rajdeep Singh
3 min readSep 28, 2021

Task 3:

  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.

To solve the above problem we must firstly install AWSCLI from the internet over our machine.

Then we have to run the command:

aws configure

This command is used to set the user and password using the AWS Access Key ID and AWS Secret Access Key provided at the time of creating the IAM user

We can get help for any command using:

  aws help
aws <command> help
aws <command> <subcommand> help
  1. To create a key pair we use the command
aws ec2 create-key-pair --key-name awscli-key

2. Creating a security group

aws ec2 create-security-group --group-name AWSCLI --description "Security group created by CLI"

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

aws ec2 run-instances --image-id ami-0a54aef4ef3b5f881 --count 1 --instance-type t2.micro --key-name awscli-key --security-groups AWSCLI

4. Create an EBS volume of 1 GB

aws ec2 create-volume --availability-zone us-east-2c --size 1 --volume-type gp2

5. Connect the EBS to ithe instance created earlier.

aws ec2 attach-volume --volume-id vol-0883a84c4a3a65960 --instance-id i-02ae91e27033e7686 --device /dev/sdf

Now that all the all the steps have been done we can cross-check it from the WebUI

  1. Created Security Group
  1. Instance created
  1. EBS volume that was created and connected to the instance

From following these steps we can launch a instance from newly created security groups and key pair that attach an external storage with it using the Command Line Interface.

--

--