In this blog we learn how to launch Instance by using Aws cli (command line interface ) by creating a key and a security group also and also learn how to create a volume and attach to the os .

Following are the steps for doing this task .

Gjgautamjoshi
5 min readNov 12, 2020

Step 1. We create a new key pair using the command

Aws ec2 create-key-pair -- key-name

We create key by Gautam name and let’s that we have any key name by such name Gautam already created or not.

In this pic we don’t have any key by Gautam name .

And let’s create key by using the following command .

We run the command successfully for creating command .

Now let’s check for confirmation key is created or not .

Yes , key successfully created our first step is done . And for login into instance it is compulsory to key name

Now we go on second step how to create security group by cli .

Step 2. How to create security group

In above step we successfully created key for login into the instance and in this step how to create security group means whom we allow to access our instance like ingress or outgress rules .

We create security group name by this command .

Aws ec2 create-security-group -- description Gautam_security --group-name gautam

Here two option “description and group name both are compulsory with these two arguments we can’t crate security group .”

Now let’s check that we have already created a security group by Gautam name or not .

We don’t have any security group name by name Gautam

Let’s create

Our command runs successfully .

Security group also created successfully by name “gautam ”

Step 3. Now we launch instance with the help of the key and security group that we have already created

By using key and ids of all other attributes like image , subnet etc

When we launch or create anything with the help of Aws cli we always use id’s and it is must because Aws only understand id’s.

We launch instance by using this command

Now let’s run this command

Command runs successfully .

Now we check that instance launched or not .

Yes , instance launch successfully .

We launch Instance successfully now our next step is to create a EBS volume so that we can attach to our instance .

Step 4. Creating EBS volume

We create a EBS volume for storing some important data and if our Instance get terminated by chance our data remains successfully.

For attaching EBS volume , volume and instance both are should be in same availablity zones .

For creating EBS volume we use this command

We also check that we have any volume of 1 GB already created or not .

No, we don’t have any volume of 1 GB

Now we run the command for creating volume .

Command runs successfully now we check that volume is crated or not in the GUI of Aws .

Yes volume crated successfully the first of size of 1 GB

We also create EBS volume now our next step is to attach this volume to the instance that we launch in the previous steps .

Step 5. How to attach EBS volume to the instance .

In this step we attach the volume that we created in earlier steps to our Instance for attaching the volume we use the this command

For attaching we need instance I’d

Volume I’d and device name with I’d of all these except device in this we need name .

We use the following command

Let’s check that the instance has already attached any volume or not .

No it doesn’t have any volume .

Now we run our command

Our command runs successfully now let’s check that volume attach or not.

Yes volume attach successfully and our task is successfully completed .

--

--