Getting Started with AWS CLI

Abhiroop Bas
3 min readOct 14, 2020

Let us me introduce a very efficient, powerful and fast way to launch two hundred instances or make a one click application.

Getting Started

Console is a thing of the past, work more efficiently and faster with the aws command line (AWSCLIV2) package downloadable from here.

before-after creating of user using CLI

To get started, use the following command to allow your command prompt to enter your aws console to work on your behalf.

aws configure

To create a new user, we use the IAM option.

aws iam create-user user-name bob

command prompt

Now we shall also need the access key to be created and then further add the user to a security group. We shall be using the admin security group to enable the user permission to use all the features.

aws iam create-access-key — user-name bob

aws iam add-user-to-group — user-name bob — group-name admin

Now we shall launch an instance using ec2 using the AMI image through the command line.

ec2 launch

aws ec2 run-instances — image-id <ami id> — instance-type <instance type, typically t2.micro is used> — count 1 — security-group-id <sg-…> — key-name <newly created key>

This shall launch a new ec2 instance with the given details, we can check that from the console.

new ec2 instance

Next we create a storage for the instance of type gp2 size 80 and put it in the same availability zone as the instance. You will know the reason for this in some time.

storage created

To create storage we use the following command

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

Now we can add this newly created storage to the newly created instance. This is the reason, we went for creating the instance in the same group.

storage attach to instance

Now the storage has been successfully attached to the instance. We did this using the following command.

aws ec2 attach-volume — volume-id <volume id found in the credentials of the storage> — instance-id <instance id, found in the instance credentials> — device <drive>

Food for thought:

The entire process can be automated by putting the commands as a script and running the script whenever a user wants to perform the following task in one click.