Complete Reference – How to Install, Configure, and Use AWS CLI

  • by

So far, we understood how can we create a personal account with AWS and we’ve seen AWS ec2 and it’s functionalities. We have familiarized ourselves with cloud terminologies for better understanding of AWS. In this article, we will perform a deep dive on AWS CLI. We will learn how to install, configure and use AWS CLI.

For those, who has not verified the other articles yet, I suggest to read those articles for better understanding.

Based on access pattern, AWS users can be classified into two distinct types –

  • Console user
  • Programmatic user

AWS Command Line Interface can be configured both for console user and for programmatic access. The programmatic user is dedicated for a service or program, hence is not allowed to login to AWS Management Console.

Installation of AWS CLI is very simple and straight forward. AWS provides a structured document to install it.

AWS Version Check

The AWS Command Line Interface is available in two versions. To identify the version you installed, simply type:

aws --version

Desired output looks like:

[dkonar@start-learning-online ~]$ aws –version
aws-cli/1.18.104 Python/3.8.5 Linux/5.4.55-1-lts botocore/1.17.27
[dkonar@start-learning-online ~]$

In my case, I’ve 1.18.104 version installed on my machine.

AWS CLI version 1 is the original AWS Command Line Interface that AWS still supports. AWS CLI version 2 is the recent development of AWS and has many features than that of version 1. New features are getting integrated with AWS CLI version 2 and are NOT back-ported to the AWS CLI version 1. Hence, it is always a good idea to install AWS CLI to version 2. You will get all those features that’d not present in AWS CLI version 1.

You have to be careful while installing AWS CLI version 2. The AWS CLI version 2 is available to install only as a bundled installer. You may find it in some package managers, however these are not produced or managed by AWS! Therefore they are not the official packages and are not supported by AWS.

Those who're having AWS CLI version 1 like me, can upgrade their CLI version to 2. AWS provides an way for update. You may follow AWS instructions by clicking me. Alternatively, you can also rely on my steps (based on AWS documentation) what I performed while upgrading the CLI version!

AWS CLI Installation Steps

Now, let’s focus how can we install AWS Command Line Interface on Linux.

(A) Download the installation bundle

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"

(B) Decompress the downloaded zip file.

unzip awscliv2.zip

(C) Install AWS CLI

sudo ./aws/install

(D) Verify installation

aws --version

Pre-requisite:

  • You must be able to extract or “unzip” the downloaded package. If your operating system doesn’t have the built-in unzip command, use an equivalent.
  • The AWS CLI version 2 uses glibc, groff, and less. These are included by default in most major distributions of Linux.
  • AWS supports the AWS CLI version 2 on 64-bit versions of recent distributions of CentOS, Fedora, Ubuntu, Amazon Linux 1, and Amazon Linux 2.
  • AWS supports the AWS Command Line Interface version 2 on Linux ARM.
  • Because AWS doesn’t maintain third-party repositories, they can’t guarantee that repositories contain the latest version of the AWS Command Line Interface.

Configuration of AWS CLI

You can configure AWS Command Line Interface quickly with a single command. You just need to type:

aws configure

It need you to provide 4 basic inputs.

AWS Access Key ID [None]:
AWS Secret Access Key [None]:
Default region name [None]:
Default output format [None]:

Access and Secret Key needs to be generated from AWS IAM console.

The Default region name identifies the AWS Region whose servers you want to send your requests to by default.

The Default output format specifies how the results are formatted. The value can be any of the values in the following list. If you don’t specify an output format, JSON is used as the default. Alternatively, you can opt YAML as well.

You can simple access your AWS resources through AWS Command Line Interface now. For example, if you want to list s3 buckets, you simple need to type

aws s3 ls

Note: Be careful, your user (programmatic or console) should have access to list S3 buckets.

If you’ve multiple AWS accounts, you can configure using profile. A collection of settings is called a profile.

To do so, you need to type:

$ aws configure --profile startlearningonline

startlearningonline is the profile name in my case.

You can then specify a –profile profile name and use the credentials and settings stored under that name.

aws s3 ls --profile startlearningonline

Configuration settings and precedence

The AWS Command Line Interface uses credentials and configuration settings located in multiple places, such as the system or user environment variables, local AWS configuration files, or explicitly declared on the command line as a parameter.

Certain locations take precedence over others.

The AWS CLI credentials and configuration settings take precedence in the following order:

  1. Command line options – You can specify in command line that will overrides settings specified in any other location
  2. Environment variables
  3. CLI credentials file
  4. CLI configuration file
  5. Container credentials
  6. Instance profile credentials

When you configure AWS Command Line Interface, two files are generated and store the inputs that you provide while configuring the CLI. You can find these two files in a folder ‘.aws’ in your user’s home directory. The configurations inputs are stored profile-wise in ‘config’ file and your secret and access keys are stored in ‘credentials’ file.

Please refer the sample config and credentials files as shown below for your reference:

~/.aws/credentials

[default]
aws_access_key_id=AKIAIOSFODNN7GONLINE
aws_secret_access_key=wQcurXUtnFEMI/K7MDENG/bPxRfiCYONLINEKEY
~/.aws/config

[default]
region=eu-west-1
output=json

You can set config parameters or credentials by applying some switch with ‘aws configure’

For example, if you want to region, you have to type

aws configure set region us-east-1 --profile startlearningonline

To remove a setting, use an empty string as the value, or manually delete the setting in your config and credentials files in a text editor.

If you find this article useful, thanks to share with those who needs it!

Tags: