Creating Key Pair, Security group and launching EC2 Instance with external EBS Volume attached using AWS CLI

Creating Key Pair, Security group and launching EC2 Instance with external EBS Volume attached using AWS CLI

AWS Command Line Interface (CLI) is a unified tool to manage your AWS services. With just one tool to download and configure, you can control multiple AWS services from the command line and automate them through scripts. AWS Command Line Interface ( AWS CLI ) allows us to interact with its web-services platform in a more flexible way. It comes with multiple number of commands which we as users can use and implement in a more customized way and get rid of the burden of doing things manually.


TASK DESCRIPTION:-

* 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


Tools Required:-

1. AWS command line interface

2.Terraform


Firstly check whether AWS CLI is installed or not using the following command

aws --version

No alt text provided for this image

AWS CLI version has successfully installed in our Windows . Now, we need to login to our AWS account from the command line using the command given below:-

aws configure
No alt text provided for this image

Now, create a new key pair "arthtaskkey" using CLI

aws ec2 create-key-pair --key-name "arthtaskkey"


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

Create Security group " arthsg" using the following command :-

aws ec2 create-security-group --group-name arthsg --description  "Allow SSH"
No alt text provided for this image
No alt text provided for this image

To Set Inbound or Ingress Rule to authorize the outside traffic ,we use the security group id of the above group using the following command:-

aws ec2 authorize-security-group-ingress --group-id sg-0f852fc29b7c737cf --protocol tcp --port 22 --cidr 0.0.0.0/0


No alt text provided for this image

We can see the above Information about Security Group in CLI using the following command:-

aws ec2 describe-security-group --group-id sg-0f852fc29b7c737cf


No alt text provided for this image

Now, launch EC2 instance with the help of following command:-

aws ec2 run-instances --image-id ami-0e306788ff2473ccb --instance-type t2.micro --key-name arthtaskkey --security-group-ids sg-0f852fc29b7c737cf --count 1
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

We have to create one EBS Volume and attach it to the EC2 Instance that we have launched

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

Attach EBS Volume to EC2 Instance using the following command:-

aws ec2  attach-volume   --volume-id vol-006ec1c8ea4d80926 --instance-id i-0e62ed895633249b3  --device /dev/sdh
No alt text provided for this image

To get the output of the command in other formats like in my case I have used yaml format thus use --output parameter

aws ec2 describe-instances  --output 


No alt text provided for this image

Finally, we have to terminate the EC2 Instance and detaching the EBS Volume with the help of following commands :-

aws ec2  detach-volume  --volume-id   vol-0d1ff11448d823e5f



aws ec2 terminate-instances --instance-ids i-042a78baa35a391d1


No alt text provided for this image


To view or add a comment, sign in

More articles by Vinit Sharma

  • Self Reflection of Expert Session

    The concepts that I have learnt from this session are as follows:- 🔰Open Source means those technologies whose codes…

  • Self Reflection of Mongo DB Workshop

    THE CONCEPTS THAT I HAVE LEARNT FROM THIS AMAZING WORKSHOP ARE GIVEN BELOW:- 🔰 To store any data…

  • SELF REFLECTION OF THE SHELL SCRIPTING WORKSHOP

    THE CONCEPTS THAT I HAVE LEARNT FROM THIS AMAZING WORKSHOP ARE GIVEN BELOW:- 🔰 Shell scripting is a programmatic way…

  • Self Reflection of AI on AWS workshop

    Following are the concepts that I have learnt through this workshop:- 🎯 AI/ML resemble to human brain as it performs…

  • ARTH-TASK 11.2

    TASK DESCRIPTION:- Create a Article, blog or Video on how industries are solving challenges using Ansible ANSIBLE:-…

  • ARTH--TASK 11 (11.1 & 11.3)

    ANSIBLE It is used for the automation purpose with the help of computer networking. The basic tasks that are done from…

  • Jenkins working and using by companies

    What is Jenkins? Jenkins — an open source automation server which enables developers around the world to reliably…

  • Industry Use Cases- Kubernetes/Openshift

    On 1st March,2021 LinuxWorld Informatics Pvt Ltd had organized an expert session on "Industry use-cases of Openshift…

  • Session feedback

    Hello Connections Expert Practical Demo Session on Ansible by two of the best experts of the industry Mr. Sreejith…

  • Kubernetes Case Study (Why and when you should use Kubernetes)

    Kubernetes is a powerful container management tool that automates the deployment and management of containers…

    2 Comments

Others also viewed

Explore content categories