Launch EC2 Instance and Attach EBS volume

Aayushi Shah
7 min readNov 15, 2020

Below steps need to be performed using AWSCLI

🔅 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 we created in the previous steps.

STEP 1 :- Create a IAM User

Give a username of your choice .Then in access type check the programmatic access to login in aws account using AWSCLI .Then in password tick the custom password for the user.

In Attach policies search for PowerUserAccess so that after login in AWSCLI user can use services like EC2 ,EBS service.

Add Tag and Value of your choice

After this step Review page opens it shows you the details of this user like access power , password, username of this user. Check all details in this review page and then if satisfied and no faults discovered then create user.

User by the name of user1 created . This page shows the access key id and the secrete access key . They are required while loging through our account in AWSCLI so click on download the .cvv to download this file . This file contains only two details access key id and the secrete access key . As shown secret access key is hidden , it is very sensitive so place and save the file at correct location.

STEP 2 :- Download and Install AWSCLI for Windows

Go to this location and click on the link provided depend on you want latest or specific version . After click on link it will automatically redirect u to the new tab and .msi file download started automatically. When download completed click on the software downloaded and start installing it.

STEP 3 :- Login in AWSCLI

To check aws version use command aws — — version

To login in AWSCLI using the access key id and secret key for newly created user use command

aws configure

Then provide the access key and secret key you have . In the default region name give the name of the region you want to launch your service. In the output format give the json format.

STEP 4 : Create Key Pair

To list all the key pairs use command

aws ec2 describe-key-pairs

As shown in the image that we have only one key with the name of hadoop_demo.

Want to create a new key with the name of new_key using AWSCLI so use command

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

As shown this command created a new key with the name of new_key.

We have again listed the keys so this also list our newly created key new_key

STEP 5 :- Create Security Group

To list all the security groups use command

aws ec2 decribe-security-groups

As shown this command listed all the security groups we have already created in this region using user1 account.

To create new security group with the name of new_sg use command

aws ec2 create-security-group — — group-name new_sg — — description new_sg

as shown this command created a new security -group with the name of new_sg

We have again listed security groups to see new created security group so it give a big list scroll down to see our newly created security group

As we scroll down we found our newly created security-group new_sg in the list

STEP 6:- Launch EC2 Instance

To list all the instances launched /we have use command

aws ec2 describe-instances

In GUI we see this much instances we have and all this instances are listed using the above command. Currently we have no instance running . Now launch a new instance.

To launch a new instance use command

aws ec2 run-instance s— — image-id i_id — — instance-type t2.micro — — subnet-id s_id — — count 1 — — key-name new_key — — security-group-ids new_sg_id

— — image-id give the image id copy from GUI.

— — instance-type give t2.micro because it is the only type that is provide free to use with 1 GB RAM 1 CPU processor and max 30 GB Root Hard Disk.

— — subnet-id give the region in which you want to launch instance but give id so copy it from GUI.

— — count 1 give the number of instances you want to launch at a time.Here we want only one instance to be launched at a time. You can also provide 2.

— — key-name provide the key name (new_key) with which you want to lauch instance.

— — security-group-ids provide the security-group id(new_sg id)

Now in the output it give that we have launched instance but it is pending because it takes time to launch any instance.

In GUI Reload the EC2 instances page . After reloading it shows one instance running .This is the instance we have launched currently.

STEP 7 :- Create EBS Volume

In the EC2 Dashboard go to volumes. In the volumes we see all the EBS volumes are already attached to different instances . But we want to launch new EBS volume and attach it to the newly created instance.

To lauch new EBS volume of 1 GB using AWSCLI use command

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

as shown this command launched the 1 GB EBS volume in the us-east-2c region

In GUI reload the EC2 volume page this is shown the new 1 GB EBS volume launched .But it have no instance attached with it.As you can see the attachement field is nill for the new EBS volume.

To list all EBS volume using AWSCLI use command

aws ec2 describe-volumes

Scroll down to see our new EBS volume of 1GB

As we scroll down we found our new EBS volume of size 1 GB

STEP 8 : — Attach EBS volume

To attach the EBS volume to new EBS volume to our new Instance use command

aws ec2 attach-volume — — device /dev/sdb — — instance-id id — — volume-id vid

as shown in the below image we first list our new instance and then copy instance id to the attach command

copy instance id to aws ec2 attach command

Then again list all EBS volumes and scroll down to find our new EBS volume

Copy the EBS volume id to again aws ec2 attach command.

After finding instance id and volume id using AWSCLI . Press ENTER to run command

After launching command it shows attaching in the output.

Before reloading the ec2 volume GUI page attachement info is empty

After reloading the ec2 volume GUI page in the attachement info field instance id is displyed.

In that instance details page

Go to the storage tab . We will find one new 1 GB storage is added to this instance.

--

--