1. Overview

When working with Amazon Web Services (AWS), the Command Line Interface (CLI) can be quite useful.

The AWS CLI provides us with an easy way to interact with the various AWS services, allowing us to write scripts to use them. For example, we can use the AWS CLI to create a bucket in S3 and then upload files to that bucket.

In this quick tutorial, we’ll learn how to install the AWS CLI on a Linux system.

2. Installation

There are two major versions of the AWS CLI for us to work with. We’ll use version 2, which ships with an embedded copy of Python, making it easier to install.

Our first step is to download the AWS CLI zip file. Let’s first use cURL to download the installation pack and save it to a zip file named awscliv2.zip:

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

When this completes, we can do a quick directory listing to confirm that the zip file downloaded successfully:

$ ls -lh
total 32M
-rw-r--r-- 1 user user 32M Apr 1 14:13 awscliv2.zip

Now, we need to unzip the file:

$ unzip awscliv2.zip

Let’s find what’s appeared in our directory:

$ ls -lh
total 32M
drwxr-xr-x 3 user user 4.0K Apr  3 22:59 aws
-rw-r--r-- 1 user user  32M Apr  1 14:13 awscliv2.zip

As expected, we have a new directory called aws with the contents of the awscliv2.zip archive.

Now, we’re ready to move ahead with the installation. We’ll need to use sudo permissions for this part.

Let’s run the install command:

$ sudo ./aws/install

We can run a test command to validate the installation:

$ aws --version
aws-cli/2.0.7 Python/3.7.3 Linux/4.4.0-1085-aws botocore/2.0.0dev11

The output shows us that the installation worked and provides us with the version number of the AWS CLI and its embedded Python.

3. Configuring the CLI

Now that we’ve installed the AWS CLI, let’s link it to our AWS account.

For this step, we’ll need some credentials from our AWS account — the AWS Access Key ID and the corresponding AWS Secret Access Key.

Let’s run the aws configure command to provide settings for our AWS CLI:

$ aws configure

This initiates an interactive configuration process that prompts us for our settings:

AWS Access Key ID [None]: AKIA2AI4TQ2FZ77WOWXJ
AWS Secret Access Key [None]: ****************************************
Default region name [None]: us-east-1
Default output format [None]: json

Here, we’ve chosen to use us-east-1 as our default region and JSON for our default output format.

When the aws configure command finishes, we can check the .aws folder in our user’s home directory to see if it worked. We’ll find two files in this folder:

$ ls -l ~/.aws
total 8
-rw------- 1 user user 43 Apr 4 13:24 config
-rw------- 1 user user 116 Apr 4 13:24 credentials

Our region and output format options are stored in the config file.

Our AWS Access Key ID and AWS Secret Access Key are stored in the credentials file.

Finally, we’re ready to test our installation.

4. Testing the Installation

We’ll check our AWS CLI is working by requesting a list of our S3 buckets:

$ aws s3 ls

If we’ve done everything correctly, we’ll see a list of all our S3 buckets:

2019-06-16 21:08:55 app.example.com
2019-12-08 19:40:51 www.example.com
2020-03-02 08:17:51 com.example.backups

And that’s it! We’ve installed, configured, and validated our AWS CLI installation.

5. Conclusion

In this tutorial, we introduced the AWS CLI and listed some of its common uses. We then moved onto completing an installation of the AWS CLI and linked it to our AWS account.

Finally, we validated that our installation and configuration was complete by interacting with the AWS S3 service to list our available buckets in S3.

There’s more information about the CLI in the official CLI reference documentation.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments