Launching an instance with ebs volume attached using cli

Launching an instance with ebs volume attached using cli

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.

step1:first we create a profile by using secret key and access key and then we create a key pair using cli by using this command:

aws ec2 create-key-pair --key-name samyakkeyaws
No alt text provided for this image

step2: after that we create security grp and then we give inbound rules so that it allow only those ports what we want not everyone and for that we use these commands

#creating security grp
aws ec2 create-security-group --description "allow 22 & 80 ports" --group-name "clisecuritygrp"
#allowing 22 and 80 port
aws ec2 authorize-security-group-ingress --group-name "clisecuritygrp" --protocol "tcp" --port 22 --cidr "0.0.0.0/0"
aws ec2 authorize-security-group-ingress --group-name "clisecuritygrp" --protocol "tcp" --port 80 --cidr "0.0.0.0/0"

No alt text provided for this image

step3:now we launch instance using above created key pair and security group by using this command

aws ec2 run-instances --image-id ami-0e306788ff2473ccb --instance-type t2.micro --subnet-id subnet-19bbd155 --count 1 --key-name samyakkeyaws --security-group-ids sg-02bb37774433cfde0
No alt text provided for this image

step4:now we create a ebs volume of 1gb using this command:

aws ec2 create-volume --availability-zone ap-south-1b --size 1 --volume-type gp2
No alt text provided for this image

step5:now we attach this ebs volume to the instance using this command:

aws ec2 attach-volume --device /dev/sdh --instance-id i-018efc2b5b062ef44 --volume-id vol-0db8246f71cd09a1c
No alt text provided for this image

After everything done correctly you can go to web ui and see that all these are created and now you can do what you want to do with ec2 instance

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Thanks for reading.......................


To view or add a comment, sign in

Others also viewed

Explore content categories