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

--

--