Launch AWS Ec2 Instance Using CLI

Sagarsharma
2 min readMar 20, 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 theinstance you created in the previous steps.

  1. Create a key pair
aws ec2  create-key-pair  --key-name Task3key

2. Create a security group

aws ec2  create-security-group  --description task3 --group-name Task3securitygroup --tag-specifications ResourceType=security-group,Tags=[{Key=Name,Value=Task3sg}]

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

aws ec2 run-instances --image-id ami-0a9d27a9f4f5c0efc --instance-type t2.micro ResourceType=instance,Tags=[{Key=Name,Value=Task3Ec2}] --count 1 --security-group-ids sg-04792cc6c3ec64178 --subnet-id subnet-6c736704 --key-name Task3key

4.Create an EBS volume of 1 GB.

aws ec2 create-volume --availability-zone ap-south-1a --size 1 --volume-type gp2 --tag-specification ResourceType=volume,Tags=[{Key=Name,Value=Task3ebs}]

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

aws ec2 attach-volume — instance-id i-003955b93da7c0aaa — volume-id vol-0c2a5ea8b190d16e3 — device /dev/sdp

Thank you!!!

--

--