Creating New Instance using Aws CLI

Rishabh
3 min readOct 14, 2020

Well we already know how to launch or even run an instance using WebUi provided by amazon and it is quite easy to do that…

But here question is what we have to automate our AWS or even to just do things with one click or with using simple commands, Yes we can definitely do that !!…. But do you know what we need if Not here we will discuss it

SO here’s our task we going to perform:

🔅 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.

Here’s the steps we need to follow to do above task.

1)Security Group id created is : “Group Id”: “sg-083b1d3f1c794c704”

To create a new security group

Creating a New Key Pair.

2)(a)Using help to check what is needed for creating key pair :AWS ec2 create-key-pair help

Using help command to create new key pair.

2)(ii)Creating a key pair with name : aws ec2 create-key-pair — key-name CLIkey

Output generated by above command

Creating a new instances and running it

REQUIREMENTS TO CRETAE A NEW INSTANCE
— AMI id : ami-052c08d70def0ac62
— Instance id : t2.micro
— Subnet : subnet-a9cdc4c1
— Availabilty zone : ap-south-1a
— Key name : CLIkey

##We will use the following command to launch/run new instance:-##
aws ec2 — image-id <id> — instance-type <type> — count <1> — subnet-id <value> — security-group-ids <sg_id> — key-name <key>.

New Instance is created with the above output

Here’s the proof that new instance is created

t2.micro instance has been created

Creating a Volume using CLI using Following Commands

aws ec2 create-volume \
— volume-type gp2 \
— size 1 \
— availability-zone ap-south-1a

New EBS volume has been created

Attaching the Above created Volume to new instance

To do so we will use help command to check all the requirements.

(a)aws ec2 attach-volume help

Options required to attach the volume to an instance.

(b)Now attaching the above volume to the instance created

aws ec2 attach-volume — device “xvdh” — instance-id i-0318d487e763fc150 — volume-id vol-0147697afc8475858

Output for attached EBS

Here’s the proof that EBS Volume has been attached and in use with Newly created Instance

1GB t2.micro has been created.

One key note : All the task are given under the guidance of “Mr. Vimal Daga”, I would like to thank him for all the efforts and knowledge passed by him to each one of us.
Everything taught till now or even in future by sir is very useful and mind blowing.
Thanking again for providing such opportunity to us for being better in technology as well as an overall human being.

--

--

Rishabh

Student from B.tech 2nd Year, A proud ARTH learner, love new technologies, Curious about many thing, likes to explore places, love eating pizza and much more.