AWS CLI

Explain how to use the AWS Command Line Interface (CLI) to interact with AWS services.

Installation

see https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html

Configuration

Depending on the file, profile section names use the following format:

Config file: [default] [profile user1]
Credentials file: [default] [user1]

Do not use the word profile when creating an entry in the credentials file.

The following examples show a credentials and config file with two profiles, region, and output specified. The first [default] is used when you run a AWS CLI command with no profile specified. The second is used when you run a AWS CLI command with the --profile user1 parameter.

~/.aws/credentials

1
2
3
4
5
6
7
[default]
aws_access_key_id=AKIAIOSFODNN7EXAMPLE
aws_secret_access_key=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

[user1]
aws_access_key_id=AKIAI44QH8DHBEXAMPLE
aws_secret_access_key=je7MtGbClwBF/2Zp9Utk/h3yCo8nvbEXAMPLEKEY

~/.aws/config

1
2
3
4
5
6
7
[default]
region=us-west-2
output=json

[profile user1]
region=us-east-1
output=text

Using the AWS CLI

Command Structure

1
aws <command> <subcommand> [options and parameters]

Basic Usage

1
aws s3 ls --profile dev

Auto Prompt mode

1
aws --cli-auto-prompt

Reference