Getting started with AWS Command Line Interface

Arpit Awasthi
4 min readOct 25, 2020

Follow this link to install aws cli version 2 for linux,windows or mac os

Creating IAM user

First we have to create an IAM user as using root credentials to login is not a good choice.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. You will be charged only for use of other AWS services by your users.To get started using IAM, or if you have already registered with AWS, go to the AWS Management Console and get started with these IAM Best Practices.

You can check aws cli version by running the command aws — version

Open IAM service in aws service list

Click on Users then Add user

Enter the details of your iam user.If you want to login from cli then tick programmatic access.Here i have selected both.

Attach policies that act as permissions.As the name says, AdministratorAccess will give access to all the service except access to billing dashboard.If you want to restrict your iam user to use iam service then you can attach PowerAccess policy.This will give the user access to all the services excluding iam service and billing dashboard.

Creating aws login profile in cli

Saved the configurations and download your access key and secret key for your iam user.

open your terminal to login to your aws account and create profiles.Login to your account by typing the command:

aws configure

Type your access id and secret key

If you have multiple iam users then you can create a profile and use any one of them particularly to run any command by running the following command:

aws configure — profile profilename

aws configure list-profiles

aws create a hidden folder by its name to save all the profiles and credentials.You can go to this folder to see your saved information by typing this command in linux:

cd ~/.aws/

Launching the instance from cli

aws team has tried to create user-friendly commands and you can use help option anywhere you stuck.

To launch the instance run the following command:

aws ec2 run-instances — image-id ami-0e306788ff2473ccb
— instance type t2.micro — count 1 — subnet-id subnet-d8aea6b0 — security-group-ids sg-of876241f8684dbf7 — key-name my_key

Here enter the image id of whatever image you want to launch.count is the replication of the os,if count is 2 then it will launch 2 instance of same os.Enter your respective subnet-id and security-group-id.

You can see from amazon ec2 dashboard your newly launched instance.

Creating new Security Group

To create a new security group under amazon’s default vpc, run the following command:

aws ec2 create-security-group — group-name MySecurityGroup — description “My security group”

It will create security group for default vpc.To create sg for specific vpc, append the above command with vpc id :

— vpc-id vpc-1a2b3c4d

Creating new EBS volume of 1 GB

EBS is a zonal service of amazon.We can attach ebs volume to ec2 instance if both the ebs volume and ec2 instance are in the same zone of the region.

To see the details of launched ec2 instances such as availability zone, use the following command:

aws ec2 describe-instances

Now create ebs volume in the same availability zone as your instance.This command will create ebs volume of 1 GB:

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

Get details about your ebs volume by using the command:

aws ec2 describe-volumes

Attaching new EBS volume to the ec2 instance

aws ec2 attach-volume — volume-id vol-1234567890abcdef0 — instance-id i-01474ef662b89480 — device /dev/sdf

Here, volume id and instance id will be your respective ebs volume and instance.

--

--