Launch instances via CLI(Command line interface) & Attaching EBS.

Amankumarabhishek
7 min readOct 18, 2020

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

| All the above steps must be performed using AWS CLI.

| WHAT IS CLI ?

→ CLI :- Command Line Input

A command-line interface processes commands to a computer program in the form of lines of text. The program which handles the interface is called a command-line interpreter or command-line processor.

| WHY AWS CLI ?

One of the main benefits is the ability to save substantial time. The savings comes in the form of easier installs, support of all services from one tool, moving beyond GUIs, and automating processes and commands with shell scripting.

→ Easy to install :- Installing from previous toolkits like the old AWS EC2 API toolkit took several steps and forced the user to set up multiple environment variables. There were plenty of places to make a wrong move and interrupt the install. One huge benefit of AWS CLI is that installation is smooth, quick, simple, and standardized.

→ Automation :- It gives you the ability to automate the entire process of controlling and managing AWS services through scripts. There are many things which the web UI can’t automate, everything is very manual. For eg- We can’t launch 2 EC2 instances from different AMI or same AMI one click.

Saves time :- GUIs are great when you’re just learning the ropes of a system. Once you get up and running, the user-friendly graphical interface tools start to stand in your way. Most users find it faster and easier to use the AWS CLI once they reach a certain level of proficiency.

| INSTALLING AND CONFIGURING AWS CLI

|Step 1 :- Install AWS CLI

Need to Install AWS CLI. You can download from link given below or Click-here.

https://awscli.amazonaws.com/AWSCLIV2.msi

After clicking AWSCLI will be getting download after that just install it and check the AWS CLI is install or not

aws — version

|Step 2 :- Login with AWS Console

Go to AWS GUI and create an account

Or if already have an account than just get login via root.

and after getting logged in go to IAM.

| Now, What is IAM ?

AWS Identity and Access Management (IAM) enables you to manage access to AWS services and resources securely. Using IAM, you can create and manage.

AWS users and groups, and use permissions to allow and deny their access to AWS resources. IAM is a feature of your AWS account offered at no additional charge.

|Step 3 :- Create User in IAM

In IAM click on User and than click on Add user as showing below :

1st click on User after that Add user

In at very next page provides the details

Provides the details which you want

In Access type allow both Programmatic access & AWS Management Console access for future and set the password for AWS Management Console access.

After that click on Next.

Click on Attach existing policies directly
Select PowerUserAccess
Give the name of key
Overview
Access key & Secret key

| Step 4 :- AWS Configure

Open CLI and run AWS configure command

Give the Access key & Secret Access key which can be taken from User id.

|Always enter the location in code

From here we can see the locaton

|STEP 5 :- Create a Key Pair

| We can also go to AWS GUI for checking key is successfully created or not.

Click on key Pairs

| Step 6 :- Create a Security Group

Security Group is similar to that firewall which will determine who can come inside and go outside the instance(operating system).

aws ec2 create-security-group --group-name MySecurityGroup --description mysecurity-group

Security group is set of rules in aws cloud where we can control inbound and outbound traffic thats why we used security group. I wrote command for creating the security group and added port 22 (for ssh) and port 80 (for webserver).

| The security group has created with no rules

In this security group there is no rule this means every service by default denied .As we want to login to instance (OS) to this security group attached we will create ingress rule or inbound rule that will allow to do so . For linux OS login we use SSH protocol .

To add the rule to allow SSH from any IP

For SSH - aws ec2 authorize-security-group-ingress --group-id sg-0e9ec2437e6c615ff --protocol tcp --port 22 --cidr 0.0.0.0/0For HTTP - >aws ec2 authorize-security-group-ingress --group-name mysecuritygroup --protocol tcp --port 80 --cidr 0.0.0.0/0
For-SSH
For-HTTP

Here we can clearly see that security group has been created but there is no inbound and outbound rule. So we have to create the rules. Lets see how to do that

|Launching an instance using the above created key pair and security group.

We know that In aws cloud launching the operating system is also known as launching the instance. So instance is similer to OS. Let’s see how to launch instance via using CLI.

aws ec2 run-instances --image-id ami-173d747e --count 1 --instance-type t1.micro --key-name MyKeyPair --security-groups my-sg

Replace the AMI_IMAGE_ID, INSTANCE_TYPE, COUNT and SECURITY_GROUP_IDS with your AMI image id , instance-type , security-group-id respectively .To tag the instance replace KEY and VALUE with key and value which you want to give .Finally replace YOUR_KEY_NAME with key name .

Press space for next / down

We can also check from the Console of AWS.

| Step 7 :- Create an EBS volume of 1 GB

What is EBS ??

EBS is exactily like a pen drive. But in aws….. EBS work as a block storage not a object storage. But pen-drive which we used in real world that is object storage not a block storage so there is not possible to launch operating system on top of object storage. But we can launch OS on top of block storage. That is a big difference between the object storage and block storage.

In aws EBS is a regional service which can be access by those instance which have same availability zone exactly like EBS availability zone. Remember this important things.

To attach the EBS volume for this run the below command

We can also check on Console

After attaching Instance with EBS. Here we can see that the EBS volume has attached to the instance.

Thanks for reading. Hope you will learn.

  • Aman Kumar Abhishek

--

--

Amankumarabhishek

Hy! I am a student of BCA. I am here for keeping my knowledge for everyone. What I learn What I want to learn all the things I am getting here.