CREATE AN INSTANCE AND ATTACH VOLUME THROUGH AWS CLI

Shubhamkhandelwal
4 min readOct 14, 2020

--

Task Description — AWS

đź”… 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 steps must be performed using AWS CLI

First of All you have to create user through IAM in AWS and get AWS Access key ID and AWS secret access group ID.

Use this below command to configure the access id and secret access id to AWS server remind that region name and output format it will take automatically or you can give region name and output format and per your requirements.

Now Start from Steps:

Step 1: → Create A key pair

When you will use the below command it will create a key pair and you can give any key name .

“aws ec2 create-key-pair — key-name aws-cli-shubham”

it will show to the AWS EC2 key pair

Step 2: → Create a security group

“ aws ec2 create security-group — group — name mysecurity — description “mysecurity” ”

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

“aws ec2 run-instances — image-id ami-0e306788ff2473ccb — count 1 — instance-type t2.micro — key-name aws-cli-shu — security-group-ids sg-0deb9c56e4afda4c3 — subnet-id subnet-fb2f51b7"

You will get image id from launch instances .

you can find subnet from there which subnet id you want to launch the instance

when you will use the above command, you will get output :-

Here the instance launched successfully , now we will go to the next step i.e. create and attach volume.

Step 4 →Create an EBS volume of 1 GB

“aws ec2 create-volume — availability-zone ap-south-1b — size 1 — volume-type gp2"

You can see no volume attached yet , Now we will attach the volume to the instances.

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

“aws ec2 attach-volume — instance-id i-0c0be020c3713e220 — volume-id vol-086a0f690f4afced9 — device /dev/sdf”

you can see the volume is attached successfully to the instances using AWS CLI.

So , the task is done successfully

hope this blog will helpful to you guys, I used every minor concept to complete this task , in case you have any query or doubt you can DM me On my LinkedIn:-https://www.linkedin.com/in/shubham-khandelwal-a04613144/

--

--

No responses yet