Getting Started with AWS-CLI

Vivek Singare
5 min readNov 3, 2020

--

aws CLIv2: Installation, Configuration and basic operations in Windows command prompt

Initially as a beginner in aws cloud we use graphical Console (WebUI provided by aws) for high level understanding. As we step ahead, in real industry case, instead of manual part (which is time consuming) we have to be very fast in terms of performance, minimizing time and manpower i.e. to achieve automation. And for automation aws console won’t help, here CLI (Command Line Interface) plays major role.

aws CLI is a command line interface tool from which we can control and perform multiple aws operations and ultimately automate whole aws part with scripts.

Install and Configure aws CLI:

Download and install aws cli latest version 2 : download link

Before configuring aws cli, first open terminal/command prompt and check version to cross check if it is installed properly -

aws --version

To configure aws cli, we must have user account (aws access key and secret key). So if you don’t have user with programmatic access, create one from aws console.

Creating User for programmatic access:

Go to IAM service and “add user”-

Click on “Add user option”

Give user name, access type- Programmatic access (programmatic access is required for cli, apart from it we can also enable console access)

Creating user form programmatic access

set permission accordingly, here I have given ‘PoweUserAccess’ -

setting permission to user

finally, here we get user credentials. This is first and last time we can get it so download and save csv file.

user created!

Configuring aws cli:

aws configure

here give generated access key and secret key and enter for by default setting

configuring aws CLI

For the demonstration of aws CLI, we will launch one instance. We are going to perform following steps using AWS CLI:

1️⃣ Create a key pair
2️⃣ Create a security group
3️⃣ Launch an instance using the above created key pair and security group
4️⃣ Create an EBS volume of 1 GB
5️⃣ Attach the above created EBS volume to the instance

General format of aws command- Every command starts with ‘aws’, then service followed by operation to perform and it’s options. Most of the commands has required options to be given. All this you can check in documentation provided by aws- https://docs.aws.amazon.com/cli/

1️⃣Creating a key pair:

To launch instance we must have key pair.

here output text option will save generated key as given file type as .pem. We can check with aws console by root user

Generated key pair

2️⃣ Creating a security group:

For an instance we must define security group

SG created

by default it will set outbound to all traffic and no inbound. According to our requirement we can set inbound rule ex. for ssh login. We have to give protocol name, port no. and cidr range.

defined inbound rule for ssh

3️⃣ Launching instance using the above created key pair and security group:

For launching instance, we need to give ami id that we can obtain from console, count as no. of instance, instance type, key name and security group id. We can also give any tag to it ex. Name

launching instance and tagging it
Instance launched successfully!

4️⃣ Creating an EBS volume:

To create new volume, mention volume type and size as we require along with availability zone. Here we have to attach this volume to above launched instance so we must create this volume in same zone as instance.

Volume created successfully!

5️⃣ Attaching the above created EBS volume to the instance:

To attach created volume to instance, mention volume id and instance id to which you want to attach volume along with device name.

Volume attached successfully!

☁ Extra Bonus

We have attached external volume to instance. But in order to use it we must perform 3 steps- Make partition, Format and Mount. Without these 3 steps, we can’t use volume.

🔑ssh login to instance: with default ec2-user and attached key. Switch user to root for admin access.

Checking formatted disks

here we can see external volume disk /dev/xvdf is attached but not is use.

〽Making Partition:

Partition created!

💽Formatting and mounting:

Formatted and mounted successfully!

here disk is formatted and it is mounted on new folder ‘/vivek’ and now it is ready to use!

PS: This is the task from a ongoing ‘AWS-CSA Training’ and I am thankful to Mr. Vimal Daga Sir for their valuable guidance.

Sign up to discover human stories that deepen your understanding of the world.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Vivek Singare
Vivek Singare

No responses yet

Write a response