Intro

In this post I will show you how to get the AWS CLI install and setup so that you can interact with AWS service via the CLI on your local machine.

Installation

At the time of writing there are two version of the AWS CLI. It is recommended to install version 2 of the software as all the dependencies are built in.

Linux Install

cmd
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install

A binary will be installed at /usr/local/aws

MacOS Install

cmd
curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"
sudo installer -pkg AWSCLIV2.pkg -target /

Test Install

You can test the installation with the aws --version command.

cmd
aws --version

# output
aws-cli/2.0.8 Python/3.7.4 Darwin/19.3.0 botocore/2.0.0dev12

AMI permissions

You will need to ensure that your user has sufficient permission to manage resources. For my personal account I have applied AdministratorAccess . This could differ for an organisation or yourself depending on how you have AMI permission setup.

API Keys

In order to interact with AWS via the CLI tools you will need to generate API keys. Generate API keys for you user in the AWS console by navigating to:

The details can be downloaded as a csv or use them in the next step before proceeding.

Note
Once you close the popup window you will not be able to see the secret key again.
Warning
Keep your AWS API keys safe, anyone with access to them can impersonate you and potentially provision services as you under your account.

Environment Variables

I prefer to set my keys as environment variables in my shell environment. I am using a zsh shell

file
# ~/.zshrc

export AWS_ACCESS_KEY_ID="SECRET_KEY_ID"
export AWS_SECRET_ACCESS_KEY="SECRET_KEY"

Ensure that your ~/.zshrc file is only readable by yourself

cmd
chmod 0600 ~/.zshrc

Source your ~/.zshrc file to load the variables into your shell environment.

cmd
source ~/.zshrc

AWS CLI Configuration

Now it's time to configure your AWS CLI environment using the aws configure command.

Note
Leave the AWS Access Key ID and AWS Secret Access Key blank since we set them as environment variables.
cmd
aws configure

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

A config file is created in the ~/.aws/ directory

file
# ~/.aws/config

[default]
region = us-east-1
output = json

Usage

Now that the AWS CLI is installed and setup for use you can begin using it. The basic command structure is aws <service> [parameters ...].

You can use the built in help to get more info on how to use a service.

cmd
aws s3 help

Example sync of files from the local file system to S3.

cmd
aws s3 sync <LOCAL_FOLDER>/ s3://<BUCKET_NAME>

Detailed docs can be found here.

Outro

The AWS CLI is a nice and handy way to interact with AWS. In some instances its the only way to interact with it. For example files larger the 160GB can only be uploaded to S3 via the CLI.

# aws