How to launch AWS EC-2 Instance from CLI and Attach the EBS Volume

Aditya N
2 min readMay 4, 2021

--

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

Step1: Creation of key pair using the following command aws ec2 create-key-pair — key-name aws_task1

Step2: Launch the instance with the above-created key-pair and security group by using the following command aws ec2 run-instances — image-id ami-0947d2ba12ee1ff75 — instance-type t2.micro — security-group-ids sg-d01642ef — key-name AWS educate

Step3: Creation of volume by using the following command aws ec2 create-volume — size 1 — availability-zone us-east-1a

we can see the volume created in the AWS console of 1 GB and in the attachment region it has not still attached to any instance

Step 4 Now we have to attach the volume to the instance we have created first by using the command was ec2 attach-volume — device /dev/sdf — instance-id i-0faeb36ccba0fdf8a — volume-id vol-01ffc336c0a1b7c6d

Finally, we can see that the volume which we launched separately has been attached to the instance which we have passed

As all these commands are executed from AWS CLI

--

--