Launch an EC2 Instances

Launch an EC2 Instances

Using all the below steps to launch an instances and attach an EBS Volume :-

1. Create a key pair

2. Create a security group

3. Launch an instance using the above

created key pair and security group.

4. Create an EBS volume of 1 GB.

5. The final step is to attach the

above created EBS volume to the

instance you created in the previous steps.

To launch an instance firstly we have to configure AWS on our CLI :-

We have to provide AWS Access Key ID & AWS Secret Access Key which we save after creating IAM user.

No alt text provided for this image

Now Creating EC2 Key Pairs :-

aws ec2 create-key-pair --key-name 'MyKeyPair' --query 'KeyMaterial' --output text > MyKeyPair.pem
No alt text provided for this image
No alt text provided for this image

In above fig. we can clearly see that our key pair is created.

Now, we have to create a security group:-

Default security group are shown in below fig:

No alt text provided for this image

To make security group we have known our vpc id:

aws ec2 describe-vpcs
No alt text provided for this image

command to create security group :

aws ec2 create-security-group --group-name roy-sg --description "roy first security group" --vpc-id vpc-71e0181a
No alt text provided for this image
No alt text provided for this image

Adding rules to security groups using following cmd:-

a. first we have to know the ip of our aws

curl https://checkip.amazonaws.com
No alt text provided for this image

b. Now adding rules

aws ec2 authorize-security-group-ingress --group-id sg-0663cd6f141b0c31b --protocol tcp --port 22 --cidr 157.47.242.90/32
No alt text provided for this image

Now, Creating an instances on aws:-

a. cmd to check any instances is present previously.

aws ec2 describe-instances


No alt text provided for this image

b. cmd to launch an instances.

aws ec2 run-instances --image-id ami-0a9d27a9f4f5c0efc --count 1 --instance-type t2.micro --key-name 'MyKeyPair' --security-group-ids sg-0663cd6f141b0c31b --subnet-id subnet-2b5fb940
No alt text provided for this image

Now, Create an EBS Volume of 1 Gib.

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

Finally, We have to attach Created EBS volume to Created Instances.

aws ec2 attach-volume --volume-id vol-0ea8d2c20060bb494 --instance-id i-0e3a5f04f9405a689 --device /dev/sdf
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Thank You!!!

To view or add a comment, sign in

Others also viewed

Explore content categories