Aws Cli
Aws Cli
Aws Cli
User Guide
AWS Command Line Interface User Guide
Amazon's trademarks and trade dress may not be used in connection with any product or service that is not
Amazon's, in any manner that is likely to cause confusion among customers, or in any manner that disparages or
discredits Amazon. All other trademarks not owned by Amazon are the property of their respective owners, who may
or may not be affiliated with, connected to, or sponsored by Amazon.
Try it now and let us know what you think. Switch to the new look >>
You can return to the original look by selecting English in the language selector above.
AWS Command Line Interface User Guide
Table of Contents
What Is the AWS CLI? ......................................................................................................................... 1
Using the Examples in this Guide ................................................................................................. 2
About Amazon Web Services ....................................................................................................... 3
Installing the AWS CLI ........................................................................................................................ 4
Installing the AWS CLI Using pip .................................................................................................. 4
Installing the AWS CLI in a Virtual Environment ............................................................................. 5
Installing the AWS CLI Using an Installer ....................................................................................... 6
Steps to Take after Installation .................................................................................................... 6
Setting the Path to Include the AWS CLI ............................................................................... 6
Configure the AWS CLI with Your Credentials ........................................................................ 6
Upgrading to the Latest Version of the AWS CLI .................................................................... 6
Uninstalling the AWS CLI .................................................................................................... 7
Detailed Instructions for Each Environment ................................................................................... 7
Linux ........................................................................................................................................ 7
Install pip ........................................................................................................................ 8
Install the AWS CLI with pip ............................................................................................... 9
Upgrading to the latest version of the AWS CLI ..................................................................... 9
Add the AWS CLI Executable to Your Command Line Path ..................................................... 10
Python ............................................................................................................................ 10
Amazon Linux .................................................................................................................. 11
Windows ................................................................................................................................. 12
Install the AWS CLI Using the MSI Installer .......................................................................... 12
Install the AWS CLI Using Python and pip on Windows ........................................................ 13
Add the AWS CLI Executable to Your Command Line Path ..................................................... 14
macOS .................................................................................................................................... 15
Prerequisites .................................................................................................................... 16
Install the AWS CLI Using the Bundled Installer .................................................................... 16
Install the AWS CLI on macOS Using pip ............................................................................. 17
Add the AWS CLI Executable to Your macOS Command Line Path ........................................... 17
Virtualenv ................................................................................................................................ 18
Bundled Installer ...................................................................................................................... 19
Prerequisites .................................................................................................................... 19
Install the AWS CLI Using the Bundled Installer .................................................................... 20
Install the AWS CLI without Sudo (Linux, macOS, or Unix) ...................................................... 21
Uninstall the AWS CLI ....................................................................................................... 21
Configuring the AWS CLI ................................................................................................................... 22
Quickly Configuring the AWS CLI ............................................................................................... 22
Access Key and Secret Access Key ....................................................................................... 22
Region ............................................................................................................................ 23
Output Format ................................................................................................................. 23
Creating Multiple Profiles .......................................................................................................... 24
Configuration Settings and Precedence ....................................................................................... 24
Configuration and Credential Files .............................................................................................. 25
Where Are Configuration Settings Stored? ........................................................................... 25
Supported config File Settings ......................................................................................... 26
Named Profiles ........................................................................................................................ 33
Using Profiles with the AWS CLI ......................................................................................... 34
Environment Variables .............................................................................................................. 34
Command Line Options ............................................................................................................ 36
Sourcing Credentials with an External Process .............................................................................. 38
Instance Metadata .................................................................................................................... 39
Using an HTTP Proxy ................................................................................................................ 40
Authenticating to a Proxy .................................................................................................. 40
Using a Proxy on Amazon EC2 Instances ............................................................................. 41
iii
AWS Command Line Interface User Guide
iv
AWS Command Line Interface User Guide
v
AWS Command Line Interface User Guide
• Linux shells – Use common shell programs such as bash, zsh, and tcshto run commands in Linux,
macOS, or Unix.
• Windows command line – On Windows, run commands in PowerShell or at the Windows command
prompt.
• Remotely – Run commands on Amazon Elastic Compute Cloud (Amazon EC2) instances through a
remote terminal such as PuTTY or SSH, or with AWS Systems Manager.
All IaaS (infrastructure as a service) AWS administration, management, and access functions in the AWS
Management Console are available in the AWS API and CLI. New AWS IaaS features and services provide
full AWS Management Console functionality through the API and CLI at launch or within 180 days of
launch.
The AWS CLI provides direct access to the public APIs of AWS services. You can explore a service's
capabilities with the AWS CLI, and develop shell scripts to manage your resources. Or, you can take what
you learn to develop programs in other languages by using the AWS SDKs.
In addition to the low-level, API-equivalent commands, several AWS services provide customizations
for the AWS CLI. Customizations can include higher-level commands that simplify using a service with a
complex API. For example, the aws s3 set of commands provide a familiar syntax for managing files in
Amazon Simple Storage Service (Amazon S3).
aws s3 cp provides a shell-like copy command, and automatically performs a multipart upload to
transfer large files quickly and resiliently.
Performing the same task with the low-level commands (available under aws s3api) would take a lot
more effort.
Depending on your use case, you might want to use one of the AWS SDKs, or the AWS Tools for
PowerShell:
1
AWS Command Line Interface User Guide
Using the Examples in this Guide
You can view—and fork—the source code for the AWS CLI on GitHub in the aws-cli repository. Join
the community of users on GitHub to provide feedback, request features, and submit your own
contributions!
• Prompt – The command prompt is typically displayed as a dollar sign followed by a space ($ ). For
commands that are Windows specific, C:\> is used as the prompt.Do not include the prompt when
you type commands.
• Directory – When commands must be executed from a specific directory, the directory name is shown
before the prompt symbol.
• User input – Command text that you should enter at the command line is formatted as user input.
• Replaceable text – Variable text, including names of resources that you choose, or IDs generated by
AWS services that you must include in commands, is formatted as replaceable text. In multiple-
line commands or commands where specific keyboard input is required, keyboard commands can also
be shown as replaceable text.
• Output – Output returned by AWS services is shown under user input, and is formatted as computer
output.
For example, the following command includes user input, replaceable text, and output.
$ aws configure
AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE
AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Default region name [None]: us-west-2
Default output format [None]: ENTER
To use this example, enter aws configure at the command line, and then press Enter. aws
configure is the command. This command is interactive, so the AWS CLI outputs lines of texts,
prompting you to enter additional information. Enter each of your access keys in turn, and then press
Enter. Then, enter an AWS Region name in the format shown, press Enter, and then press Enter a final
time to skip the output format setting. The final Enter command is shown as replaceable text because
there is no user input for that line. Otherwise, it would be implied.
The following example shows a simple noninteractive command with output from the service in JSON
format.
To use this example, enter the full text of the command (the highlighted text after the prompt), and then
press Enter. The name of the security group, my-sg, is replaceable. In this case, you can use the group
name as shown, but you probably want to use a more descriptive name.
2
AWS Command Line Interface User Guide
About Amazon Web Services
Note
Arguments that must be replaced (such as AWS Access Key ID), and those that should be
replaced (such as group name), are both shown as replaceable text in italics. If an
argument must be replaced, it's noted in the text that describes the example.
The JSON document, including the curly braces, is output. If you configure your CLI to output in text or
table format, the output will be formatted differently. JSON is the default output format.
3
AWS Command Line Interface User Guide
Installing the AWS CLI Using pip
Prerequisites
Note
Earlier versions of Python might not work with all AWS services. If you see
InsecurePlatformWarning or deprecation notices when you install or use the AWS CLI,
update to a newer version.
You can find the version number of the most recent CLI at: https://github.com/aws/aws-cli/blob/
master/CHANGELOG.rst.
In this guide, the commands shown assume you have Python v3 installed and the pip commands shown
use the pip3 version.
The AWS CLI is updated frequently with support for new services and commands. To determine whether
you have the latest version, see the releases page on GitHub.
If you already have pip and a supported version of Python, you can install the AWS CLI by using the
following command. If you have Python version 3+ installed, we recommend that you use the pip3
command.
The --upgrade option tells pip3 to upgrade any requirements that are already installed. The --user
option tells pip3 to install the program to a subdirectory of your user directory to avoid modifying
libraries used by your operating system.
We recommend that you regularly check to see if there is a new version of the AWS CLI and upgrade to it
when you can.
4
AWS Command Line Interface User Guide
Installing the AWS CLI in a Virtual Environment
Use the pip3 list -o command to check which packages are "outdated':
$ aws --version
aws-cli/1.16.170 Python/3.7.3 Linux/4.14.123-111.109.amzn2.x86_64 botocore/1.12.160
$ pip3 list -o
Package Version Latest Type
---------- -------- -------- -----
awscli 1.16.170 1.16.198 wheel
botocore 1.12.160 1.12.188 wheel
Because the previous command shows that there is a newer version of the AWS CLI available, you can run
pip3 install --upgrade to get the latest version:
5
AWS Command Line Interface User Guide
Installing the AWS CLI Using an Installer
On Windows, you can also use the MSI installer (p. 12). Both of these methods simplify the initial
installation. However, the tradeoff is that it's more difficult to upgrade when a new version of the AWS
CLI is released.
• Linux – Add the AWS CLI Executable to Your Command Line Path (p. 10)
• Windows – Add the AWS CLI Executable to Your Command Line Path (p. 14)
• macOS – Add the AWS CLI Executable to Your macOS Command Line Path (p. 17)
Verify that the AWS CLI installed correctly by running aws --version.
$ aws --version
aws-cli/1.16.116 Python/3.6.8 Linux/4.14.77-81.59-amzn2.x86_64 botocore/1.12.106
You store credential information locally by defining profiles (p. 33) in the AWS CLI configuration
files (p. 25), which are stored by default in your user's home directory. For more information, see
Configuring the AWS CLI (p. 22).
Note
If you are running in an Amazon EC2 instance, credentials can be automatically retrieved from
the instance metadata. For more information, see Instance Metadata (p. 39).
6
AWS Command Line Interface User Guide
Uninstalling the AWS CLI
If you don't have Python and pip, use the procedure for your environment.
If you already have pip, follow the instructions in the main installation topic (p. 4). Run pip --
version to see if your version of Linux already includes Python and pip. We recommend that if you
have Python version 3+ installed, that you use the pip3 command.
$ pip3 --version
If you don't already have pip installed, check which version of Python is installed.
$ python --version
or
$ python3 --version
If you don't already have Python 2 version 2.6.5+ or Python 3 version 3.3+, you must first install
Python (p. 10). If you do have Python installed, proceed to installing pip and the AWS CLI.
Sections
• Install pip (p. 8)
• Install the AWS CLI with pip (p. 9)
• Upgrading to the latest version of the AWS CLI (p. 9)
• Add the AWS CLI Executable to Your Command Line Path (p. 10)
7
AWS Command Line Interface User Guide
Install pip
Install pip
If you don't already have pip installed, you can install it by using the script that the Python Packaging
Authority provides.
To install pip
1. Use the curl command to download the installation script. The following command uses the -O
(capital letter O) parameter to specify that the downloaded file is to be stored in the current folder
using the same name it has on the remote host.
$ curl -O https://bootstrap.pypa.io/get-pip.py
2. Run the script with Python to download and install the latest version of pip and other required
support packages.
or
When you include the --user switch, the script installs pip to the path ~/.local/bin.
3. Ensure the folder that contains pip is part of your PATH variable.
a. Find your shell's profile script in your user folder. If you're not sure which shell you have, run echo
$SHELL.
$ ls -a ~
. .. .bash_logout .bash_profile .bashrc Desktop Documents Downloads
export PATH=~/.local/bin:$PATH
This command inserts the path, ~/.local/bin in this example, at the front of the existing PATH
variable.
c. Reload the profile into your current session to put those changes into effect.
$ source ~/.bash_profile
$ pip3 --version
pip 19.0.3 from ~/.local/lib/python3.7/site-packages (python 3.7)
8
AWS Command Line Interface User Guide
Install the AWS CLI with pip
When you use the --user switch, pip installs the AWS CLI to ~/.local/bin.
$ aws --version
aws-cli/1.16.116 Python/3.6.8 Linux/4.14.77-81.59-amzn2.x86_64 botocore/1.12.106
If you get an error, see Troubleshooting AWS CLI Errors (p. 111).
Use the pip list -o command to check which packages are "outdated':
$ aws --version
aws-cli/1.16.170 Python/3.7.3 Linux/4.14.123-111.109.amzn2.x86_64 botocore/1.12.160
$ pip3 list -o
Package Version Latest Type
---------- -------- -------- -----
awscli 1.16.170 1.16.198 wheel
botocore 1.12.160 1.12.188 wheel
Because the previous command shows that there is a newer version of the AWS CLI available, you can run
pip install --upgrade to get the latest version:
9
AWS Command Line Interface User Guide
Add the AWS CLI Executable to Your Command Line Path
You can verify which folder pip installed the AWS CLI to by running the following command.
$ which aws
/home/username/.local/bin/aws
If you omitted the --user switch and so didn't install in user mode, the executable might be in the bin
folder of your Python installation. If you don't know where Python is installed, run this command.
$ which python
/usr/local/bin/python
The output might be the path to a symlink, not to the actual executable. Run ls -al to see where it
points.
$ ls -al /usr/local/bin/python
/usr/local/bin/python -> ~/.local/Python/3.6/bin/python3.6
If this is the same folder you added to the path in step 3 in Install pip (p. 8), you're done. Otherwise,
perform those same steps 3a–3c again, adding this additional folder to the path.
$ python --version
or
10
AWS Command Line Interface User Guide
Amazon Linux
$ python3 --version
Note
If your Linux distribution came with Python, you might need to install the Python developer
package to get the headers and libraries required to compile extensions, and install the
AWS CLI. Use your package manager to install the developer package (typically named
python-dev or python-devel).
2. If Python 2.7 or later is not installed, install Python with your distribution's package manager. The
command and package name varies:
• On Debian derivatives such as Ubuntu, use apt. Check the apt repository for the versions of
Python available to you. Then, run a command similar to the following, substituting the correct
package name:
• On Red Hat and derivatives, use yum. Check the yum repository for the versions of Python
available to you. Then, run a command similar to the following, substituting the correct package
name:
• On SUSE and derivatives, use zypper. Check the repository for the versions of Python available to
you. Then. run a command similar to the following, substituting the correct package name:
See the documentation for your system's package manager and for Python for more information
about where it is installed and how to use it.
3. Open a command prompt or shell and run the following command to verify that Python installed
correctly.
$ python3 --version
Python 3.6.8
$ aws --version
aws-cli/1.16.116 Python/3.6.8 Linux/4.14.77-81.59.amzn2.x86_64 botocore/1.12.106
Important
Using sudo to complete a command grants the command full access to your system. We
recommend using that command only when no more secure option exists. For commands like
pip, we recommend that you avoid using sudo by using a Python virtual environment (venv) or
by specifying the --user option to install in the user's folders instead of the system's folders.
If you use the yum package manager, you can install the AWS CLI with the command: yum install
aws-cli. You can use the command: yum update to get the latest version available in the yum
repository.
11
AWS Command Line Interface User Guide
Windows
Note
The yum repository is not owned or maintained by Amazon and might not contain the latest
version. Instead, we recommend that you use pip to get the latest version.
Prerequisites
Verify that Python and pip are already installed. For more information, see Install the AWS CLI on
Linux (p. 7).
1. Use pip3 install to install the latest version of the AWS CLI. We recommend that if you have
Python version 3+ installed that you use pip3. If you run the command from within a Python virtual
environment (venv), then you don't need to use the --user option.
$ export PATH=/home/ec2-user/.local/bin:$PATH
Add this command to the end of your profile's startup script (for example, ~/.bashrc) to persist the
change between command line sessions.
3. Verify that you're running new version with aws --version.
$ aws --version
aws-cli/1.16.116 Python/3.6.8 Linux/4.14.77-81.59.amzn2.x86_64 botocore/1.12.106
Sections
• Install the AWS CLI Using the MSI Installer (p. 12)
• Install the AWS CLI Using Python and pip on Windows (p. 13)
• Add the AWS CLI Executable to Your Command Line Path (p. 14)
When updates are released, you must repeat the installation process to get the latest version of the AWS
CLI. To update frequently, consider using pip (p. 13) for easier updates.
12
AWS Command Line Interface User Guide
Install the AWS CLI Using Python and pip on Windows
Note
The MSI installer for the AWS CLI doesn't work with Windows Server 2008 (version
6.0.6002). Use pip (p. 13) to install with this version of Windows Server.
2. Run the downloaded MSI installer or the setup file.
3. Follow the onscreen instructions.
Don't include the prompt symbol (C:\>, shown above) when you type a command. These are included in
program listings to differentiate commands that you type from output returned by the CLI. The rest of
this guide uses the generic prompt symbol, $ , except in cases where a command is Windows-specific.
If Windows is unable to find the program, you might need to close and reopen the command prompt to
refresh the path, or add the installation directory to your PATH (p. 14) environment variable manually.
You can also launch the Programs and Features program from the command line with the following
command.
C:\> appwiz.cpl
1. Download the Python Windows x86-64 installer from the downloads page of Python.org.
13
AWS Command Line Interface User Guide
Add the AWS CLI Executable to Your Command Line Path
The installer installs Python in your user folder and adds its program folders to your user path.
If you use Python version 3+, we recommend that you use the pip3 command.
If this command returns a response, then you should be ready to run the tool. The where command, by
default, shows where in the system PATH it found the specified program:
You can find where the aws program is installed by running the following command.
If instead, the where command returns the following error, then it is not in the system PATH and you
can't run it by simply typing its name.
14
AWS Command Line Interface User Guide
macOS
In that case, run the where command with the /R path parameter to tell it to search all folders, and
look then you must add the path manually. Use the command line or Windows Explorer to discover
where it is installed on your computer.
The paths that show up depend on which method you used to install the AWS CLI.
Note
Folder names that include version numbers can vary. The examples above reflect the use of
Python version 3.7. Replace as needed with the version number you are using.
Sections
• Prerequisites (p. 16)
• Install the AWS CLI Using the Bundled Installer (p. 16)
• Install the AWS CLI on macOS Using pip (p. 17)
15
AWS Command Line Interface User Guide
Prerequisites
• Add the AWS CLI Executable to Your macOS Command Line Path (p. 17)
Prerequisites
• Python 2 version 2.6.5+ or Python 3 version 3.3+
$ python --version
If your computer doesn't already have Python installed, or if you want to install a different version of
Python, follow the procedure in Install the AWS CLI on Linux (p. 7).
Here are the steps described below in one easy to copy-and-paste group. See the descriptions of each
line in the steps that follow.
1. Download the AWS CLI Bundled Installer to a file in your current working folder.
2. Unzip the package to a folder with the same name in your current working folder.
$ unzip awscli-bundle.zip
Note
If you don't have unzip, use your favorite package manager to install it or an equivalent.
3. Run the install program. This command installs the AWS CLI to /usr/local/aws and creates the
symlink aws in the /usr/local/bin directory. Using the -b option to create a symlink eliminates
the need to specify the install directory in the user's $PATH variable. This should enable all users to
call the AWS CLI by typing aws from any directory.
Note
By default, the install script runs under the system's default version of Python. If you have
installed an alternative version of Python and want to use that to install the AWS CLI, run
the install script and specify that version by including the absolute path to the Python
application. For example:
16
AWS Command Line Interface User Guide
Install the AWS CLI on macOS Using pip
$ ./awscli-bundle/install -h
$ pip3 --version
1. Download and install the latest version of Python from the downloads page of Python.org.
2. Download and run the pip3 installation script provided by the Python Packaging Authority.
$ curl -O https://bootstrap.pypa.io/get-pip.py
$ python3 get-pip.py --user
3. Use your newly installed pip3 to install the AWS CLI. We recommend that if you use Python version
3+, that you use the pip3 command.
$ aws --version
AWS CLI 1.16.116 (Python 3.6.8)
If the program isn't found, add it to your command line path (p. 17).
Example AWS CLI install location - macOS with Python 3.6 and pip (user mode)
~/Library/Python/3.7/bin
Substitute the version of Python that you have for the version in the example above.
$ which python
17
AWS Command Line Interface User Guide
Virtualenv
/usr/local/bin/python
The output might be the path to a symlink, not the actual program. Run ls -al to see where it points.
$ ls -al /usr/local/bin/python
~/Library/Python/3.7/bin/python3.6
pip installs programs in the same folder that contains the Python application. Add this folder to your
PATH variable.
1. Find your shell's profile script in your user folder. If you're not sure which shell you have, run echo
$SHELL.
$ ls -a ~
. .. .bash_logout .bash_profile .bashrc Desktop Documents Downloads
export PATH=~/.local/bin:$PATH
This command adds a path, ~/.local/bin in this example, to the current PATH variable.
3. Load the updated profile into your current session.
$ source ~/.bash_profile
$ virtualenv ~/cli-ve
Alternatively, you can use the -p option to specify a version of Python other than the default.
18
AWS Command Line Interface User Guide
Bundled Installer
$ source ~/cli-ve/bin/activate
Windows
$ %USERPROFILE%\cli-ve\Scripts\activate
$ aws --version
aws-cli/1.16.116 Python/3.6.8 Linux/4.14.77-81.59-amzn2.x86_64 botocore/1.12.106
You can use the deactivate command to exit the virtual environment. Whenever you start a new
session, you must reactivate the environment.
Sections
• Prerequisites (p. 19)
• Install the AWS CLI Using the Bundled Installer (p. 20)
• Install the AWS CLI without Sudo (Linux, macOS, or Unix) (p. 21)
• Uninstall the AWS CLI (p. 21)
Prerequisites
• Linux, macOS, or Unix
• Python 2 version 2.6.5+ or Python 3 version 3.3+
$ python --version
19
AWS Command Line Interface User Guide
Install the AWS CLI Using the Bundled Installer
If your computer doesn't already have Python installed, or you would like to install a different version of
Python, follow the procedure in Install the AWS CLI on Linux (p. 7).
• https://s3.amazonaws.com/aws-cli/awscli-bundle.zip
Here are a summary of the installation commands explained below that you can cut and paste to run as a
single set of commands.
Follow these steps from the command line to install the AWS CLI using the bundled installer.
1. Download the AWS CLI Bundled Installer using the following command:
$ unzip awscli-bundle.zip
Note
If you don't have unzip, use your Linux distribution's built-in package manager to install it.
3. Run the install executable.
Note
By default, the install script runs under the system default version of Python. If you have
installed an alternative version of Python and want to use that to install the AWS CLI, run
the install script with that version by absolute path to the Python executable. For example:
The installer installs the AWS CLI at /usr/local/aws and creates the symlink aws at the /usr/local/
bin directory. Using the -b option to create a symlink eliminates the need to specify the install directory
in the user's $PATH variable. This should enable all users to call the AWS CLI by typing aws from any
directory.
$ ./awscli-bundle/install -h
20
AWS Command Line Interface User Guide
Install the AWS CLI without Sudo (Linux, macOS, or Unix)
This installs the AWS CLI to the default location (~/.local/lib/aws) and creates a symbolic link
(symlink) at ~/bin/aws. Make sure that ~/bin is in your PATH environment variable for the symlink to
work.
$ echo $PATH | grep ~/bin // See if $PATH contains ~/bin (output will be empty if it
doesn't)
$ export PATH=~/bin:$PATH // Add ~/bin to $PATH if necessary
Tip
To ensure that your $PATH settings are retained between sessions, add the export line to your
shell profile (~/.profile, ~/.bash_profile, and so on).
21
AWS Command Line Interface User Guide
Quickly Configuring the AWS CLI
Sections
• Quickly Configuring the AWS CLI (p. 22)
• Creating Multiple Profiles (p. 24)
• Configuration Settings and Precedence (p. 24)
• Configuration and Credential Files (p. 25)
• Named Profiles (p. 33)
• Environment Variables (p. 34)
• Command Line Options (p. 36)
• Sourcing Credentials with an External Process (p. 38)
• Instance Metadata (p. 39)
• Using an HTTP Proxy (p. 40)
• Using an IAM Role in the AWS CLI (p. 41)
• Command Completion (p. 46)
$ aws configure
AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE
AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Default region name [None]: us-west-2
Default output format [None]: json
When you type this command, the AWS CLI prompts you for four pieces of information (access key, secret
access key, AWS Region, and output format). These are described in the following sections. The AWS
CLI stores this information in a profile (a collection of settings) named default. The information in the
default profile is used any time you run an AWS CLI command that doesn't explicitly specify a profile to
use.
22
AWS Command Line Interface User Guide
Region
Access keys consist of an access key ID and secret access key, which are used to sign programmatic
requests that you make to AWS. If you don't have access keys, you can create them from the AWS
Management Console. As a best practice, do not use the AWS account root user access keys for any task
where it's not required. Instead, create a new administrator IAM user with access keys for yourself.
The only time that you can view or download the secret access key is when you create the keys. You
cannot recover them later. However, you can create new access keys at any time. You must also have
permissions to perform the required IAM actions. For more information, see Permissions Required to
Access IAM Resources in the IAM User Guide.
1. Sign in to the AWS Management Console and open the IAM console at https://
console.aws.amazon.com/iam/.
2. In the navigation pane, choose Users.
3. Choose the name of the user whose access keys you want to create, and then choose the Security
credentials tab.
4. In the Access keys section, choose Create access key.
5. To view the new access key pair, choose Show. You will not have access to the secret access key again
after this dialog box closes. Your credentials will look something like this:
Keep the keys confidential in order to protect your AWS account and never email them. Do not share
them outside your organization, even if an inquiry appears to come from AWS or Amazon.com. No
one who legitimately represents Amazon will ever ask you for your secret key.
7. After you download the .csv file, choose Close. When you create an access key, the key pair is active
by default, and you can use the pair right away.
Related topics
Region
The Default region name identifies the AWS Region whose servers you want to send your requests
to by default. This is typically the Region closest to you, but it can be any Region. For example, you can
type us-west-2 to use US West (Oregon). This is the Region that all later requests are sent to, unless
you specify otherwise in an individual command.
Note
You must specify an AWS Region when using the AWS CLI, either explicitly or by setting a
default Region. For a list of the available Regions, see Regions and Endpoints. The Region
designators used by the AWS CLI are the same names that you see in AWS Management Console
URLs and service endpoints.
Output Format
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.
23
AWS Command Line Interface User Guide
Creating Multiple Profiles
Then, when you run a command, you can omit the --profile option and use the credentials and
settings stored in the default profile.
$ aws s3 ls
Or you can specify a --profile profilename and use the credentials and settings stored under that
name.
To update any of your settings, simply run aws configure again (with or without the --profile
parameter, depending on which profile you want to update) and enter new values as appropriate. The
next sections contain more information about the files that aws configure creates, additional settings,
and named profiles.
1. Command line options (p. 36) – You can specify --region, --output, and --profile as
parameters on the command line.
2. Environment variables (p. 34) – You can store values in the environment variables:
AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_SESSION_TOKEN. If they are present,
they are used.
3. The CLI credentials file (p. 25) – This is one of the files that is updated when you run the
command aws configure. The file is located at ~/.aws/credentials on Linux, macOS, or Unix,
24
AWS Command Line Interface User Guide
Configuration and Credential Files
For example, the following commands list the contents of the .aws folder.
$ ls ~/.aws
Windows
The AWS CLI uses two files to store the sensitive credential information (in ~/.aws/credentials)
separated from the less sensitive configuration options (in ~/.aws/config).
You can specify a non-default location for the config file by setting the AWS_CONFIG_FILE
environment variable to another local path. See Environment Variables (p. 34) for details.
25
AWS Command Line Interface User Guide
Supported config File Settings
The files generated by the CLI for the profile configured in the previous section look like this.
~/.aws/credentials
[default]
aws_access_key_id=AKIAIOSFODNN7EXAMPLE
aws_secret_access_key=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
~/.aws/config
[default]
region=us-west-2
output=json
Note
The preceding examples show the files with a single, default profile. For examples of the files
with multiple named profiles, see Named Profiles (p. 33).
When you use a shared profile that specifies an IAM role, the AWS CLI calls the AWS STS AssumeRole
operation to retrieve temporary credentials. These credentials are then stored (in ~/.aws/cli/cache).
Subsequent AWS CLI commands use the cached temporary credentials until they expire, and at that
point the AWS CLI automatically refreshes the credentials.
The following settings are supported in the config file. The values listed in the specified (or default)
profile are used unless they are overridden by the presence of an environment variable with the same
name, or a command line option with the same name.
You can configure these settings by editing the config file directly with a text editor, or by using the aws
configure set command. Specify the profile that you want to modify with the --profile setting.
For example, the following command sets the region setting in the profile named integ.
You can also retrieve the value for any setting by using the get subcommand.
If the output is empty, then the setting is not explicitly set and uses the default value.
26
AWS Command Line Interface User Guide
Supported config File Settings
Global Settings
aws_access_key_id (p. 22)
Specifies the AWS access key used as part of the credentials to authenticate the command
request. Although this can be stored in the config file, we recommend that you store this in the
credentials file.
Can be overridden by the AWS_ACCESS_KEY_ID environment variable. Note that you can't specify
the access key ID as a command line option.
aws_access_key_id = 123456789012
Specifies the AWS secret key used as part of the credentials to authenticate the command
request. Although this can be stored in the config file, we recommend that you store this in the
credentials file.
Can be overridden by the AWS_SECRET_ACCESS_KEY environment variable. Note that you can't
specify the secret access key as a command line option.
aws_secret_access_key = wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Specifies the Amazon Resource Name (ARN) of an IAM role that you want to use to run the AWS CLI
commands. You must also specify one of the following parameters to identify the credentials that
have permission to assume this role:
• source_profile
• credential_source
role_arn = arn:aws:iam::123456789012:role/role-name
Specifies a named profile with long-term credentials that the AWS CLI can use to assume a role
that you specified with the role_arn parameter. You cannot specify both source_profile and
credential_source in the same profile.
source_profile = production-profile
Used within EC2 instances or EC2 containers to specify where the AWS CLI can find credentials
to use to assume the role you specified with the role_arn parameter. You cannot specify both
source_profile and credential_source in the same profile.
credential_source = Ec2InstanceMetadata
27
AWS Command Line Interface User Guide
Supported config File Settings
Specifies the name to attach to the role session. This value is provided to the
RoleSessionName parameter when the AWS CLI calls the AssumeRole operation, and
becomes part of the assumed role user ARN: arn:aws:sts::123456789012:assumed-
role/role_name/role_session_name. This is an optional parameter. If you do not provide this
value, a session name is generated automatically. This name appears in AWS CloudTrail logs for
entries associated with this session.
role_session_name = maria_garcia_role
The identification number of an MFA device to use when assuming a role. This is mandatory
only if the trust policy of the role being assumed includes a condition that requires MFA
authentication. The value can be either a serial number for a hardware device (such as
GAHT12345678) or an Amazon Resource Name (ARN) for a virtual MFA device (such as
arn:aws:iam::123456789012:mfa/user).
duration_seconds
Specifies the maximum duration of the role session, in seconds. The value can range from 900
seconds (15 minutes) up to the maximum session duration setting for the role (which can be a
maximum of 43200). This is an optional parameter and by default, the value is set to 3600 seconds.
aws_session_token
Specifies an AWS session token. A session token is required only if you manually specify temporary
security credentials. Although this can be stored in the config file, we recommend that you store
this in the credentials file.
Can be overridden by the AWS_SESSION_TOKEN environment variable. You can't specify the session
token as a command line option.
aws_session_token = AQoEXAMPLEH4aoAH0gNCAPyJxz4BlCFFxWNE1OPTgk5TthT
+FvwqnKwRcOIfrRh3c/LTo6UDdyJwOOvEVPvLXCrrrUtdnniCEXAMPLE/
IvU1dYUg2RVAJBanLiHb4IgRmpRV3zrkuWJOgQs8IZZaIv2BXIa2R4Olgk
A unique identifier that is used by third parties to assume a role in their customers' accounts. This
maps to the ExternalId parameter in the AssumeRole operation. This parameter is optional
unless the trust policy for the role specifies that ExternalId must be a specific value.
ca_bundle
Specifies a CA certificate bundle (a file with the .pem extension) that is used to verify SSL
certificates.
ca_bundle = dev/apps/ca-certs/cabundle-2019mar05.pem
cli_follow_urlparam
Specifies whether the CLI attempts to follow URL links in command line parameters that begin with
http:// or https://. When enabled, the retrieved content is used as the parameter value instead
of the URL.
28
AWS Command Line Interface User Guide
Supported config File Settings
• true: This is the default value. When configured, any string parameters that begin with http://
or https:// are fetched and any downloaded content is used as the parameter value for the
command.
• false: The CLI does not treat parameter string values that begin with http:// or https://
differently from other strings.
This entry does not have an equivalent environment variable or command line option.
cli_follow_urlparam = false
cli_timestamp_format
Specifies the format of timestamp values included in the output. You can specify either of the
following values:
• none: This is the default value. Displays the timestamp value exactly how received in the HTTP
query response.
• iso8601: Reformat the timestamp as specified by ISO 8601.
This entry does not have an equivalent environment variable or command line option.
cli_timestamp_format = iso8601
Specifies an external command that the CLI runs to generate or retrieve authentication credentials
to use for this command. The command must return the credentials in a specific format. For
more information about how to use this setting, see Sourcing Credentials with an External
Process (p. 38).
This entry does not have an equivalent environment variable or command line option.
Specifies the path to a file which contains an OAuth 2.0 access token or OpenID Connect ID token
that is provided by an identity provider. The AWS CLI loads the contents of this file and passes it as
the WebIdentityToken argument to the AssumeRoleWithWebIdentity operation.
output (p. 23)
Specifies the default output format for commands requested using this profile. You can specify any
of the following values:
• json: This is the default value. The output is formatted as a JSON string.
• text: The output is formatted as multiple lines of tab-separated string values, which can be
useful if you want to pass the output to a text processor, like grep, sed, or awk.
• table: The output is formatted as a table using the characters +|- to form the cell borders. It
typically presents the information in a "human-friendly" format that is much easier to read than
the others, but not as programmatically useful.
output = table
29
AWS Command Line Interface User Guide
Supported config File Settings
parameter_validation
Specifies whether the CLI client attempts to validate parameters before sending them to the AWS
service endpoint.
• true: This is the default value. When configured, the CLI performs local validation of command
line parameters.
• false: When configured, the CLI does not validate command line parameters before sending them
to the AWS service endpoint.
This entry does not have an equivalent environment variable or command line option.
parameter_validation = false
Specifies the default AWS Region to send requests to for commands requested using this profile.
You can specify any of the region codes available for the chosen service as listed at AWS Regions and
Endpoints in the Amazon Web Services General Reference.
region = us-west-2
tcp_keepalive
This entry does not have an equivalent environment variable or command line option.
tcp_keepalive = false
api_versions
Some AWS services maintain multiple API versions to support backwards compatibility. By default,
CLI commands use the latest available API version. You can specify an API version to use for a profile
by including the api_versions setting in the config file.
This is a "nested" setting that is followed by one or more indented lines that each identify one AWS
service and the API version to use. Refer to the documentation for each service to understand which
API versions are available.
The following example shows how to specify an API version for two AWS services. These API versions
are used only for commands that run under the profile that contains these settings.
api_versions =
ec2 = 2015-03-01
cloudfront = 2015-09-017
30
AWS Command Line Interface User Guide
Supported config File Settings
operation. The aws s3 transfer commands cp, sync, mv, and rm have additional settings you can use to
control S3 transfers.
All of these options can be configured by specifying the s3 nested setting in your config file. Each
setting is then indented on its own line.
Note
These settings are entirely optional. You should be able to successfully use the aws s3 transfer
commands without configuring any of these settings. These settings are provided to enable you
to tune for performance or to account for the specific environment where you are running these
aws s3 commands.
use_accelerate_endpoint
Use the Amazon S3 Accelerate endpoint for all s3 and s3api commands. The default value is false.
This is mutually exclusive with the use_dualstack_endpoint setting.
If set to true, the CLI directs all Amazon S3 requests to the S3 Accelerate endpoint at s3-
accelerate.amazonaws.com. To use this endpoint, you must enable your bucket to use S3
Accelerate. All requests are sent using the virtual style of bucket addressing: my-bucket.s3-
accelerate.amazonaws.com. Any ListBuckets, CreateBucket, and DeleteBucket
requests aren't sent to the Accelerate endpoint as that endpoint doesn't support those operations.
This behavior can also be set if the --endpoint-url parameter is set to https://s3-
accelerate.amazonaws.com or http://s3-accelerate.amazonaws.com for any s3 or s3api
command.
use_dualstack_endpoint
Use the Amazon S3 dual IPv4 / IPv6 endpoint for all s3 and s3api commands. The default value is
false. This is mutually exclusive with the use_accelerate_endpoint setting.
If set to true, the CLI directs all Amazon S3 requests to the dual IPv4 / IPv6 endpoint for the
configured region.
addressing_style
Specifies which addressing style to use. This controls if the bucket name is in the hostname or part
of the URL. Value values are: path, virtual, and auto. The default value is auto.
There are two styles of constructing an S3 endpoint. The first is called virtual and includes the
bucket name as part of the hostname. For example: https://bucketname.s3.amazonaws.com.
Alternatively, with the path style, you treat the bucket name as if it was a path in the URI. For
example: https://s3.amazonaws.com/bucketname. The default value in the CLI is to use
auto, which attempts to use the virtual style where it can, but will fall back to path style when
required. For example, if your bucket name is not DNS compatible, the bucket name cannot be
part of the hostname and must be in the path. With auto, the CLI will detect this condition and
automatically switch to path style for you. If you set the addressing style to path, you must then
ensure that the AWS Region you configured in the AWS CLI matches the region of your bucket.
payload_sigining_enabled
Specifies whether to SHA256 sign sigv4 payloads. By default, this is disabled for streaming uploads
(UploadPart and PutObject) when using https. By default, this is set to false for streaming
uploads (UploadPart and PutObject), but only if a ContentMD5 is present (it is generated by
default) and the endpoint uses HTTPS.
If set to true, S3 requests receive additional content validation in the form of a SHA256 checksum
which is calculated for you and included in the request signature. If set to false, the checksum
isn't calculated. Disabling this can be useful to reduce the performance overhead created by the
checksum calculation.
31
AWS Command Line Interface User Guide
Supported config File Settings
The following settings apply only to commands in the s3 namespace command set:
max_concurrent_requests
Specifies the maximum number of concurrent requests. The default value is 10.
The aws s3 transfer commands are multithreaded. At any given time, multiple Amazon S3 requests
can be running. For example, when you use the command aws s3 cp localdir s3://bucket/
--recursive to upload files to an S3 bucket, the AWS CLI can upload the files localdir/file1,
localdir/file2, and localdir/file3 in parallel. The setting max_concurrent_requests
specifies the maximum number of transfer operations that can run at the same time.
Specifies the maximum number of tasks in the task queue. The default value is 1000.
The AWS CLI internally uses a model where it queues up S3 tasks that are then executed by
consumers whose numbers are limited by max_concurrent_requests. A task generally maps to a
single S3 operation. For example, as task could be a PutObjectTask, or a GetObjectTask, or an
UploadPartTask. The rate at which tasks are added to the queue can be much faster than the rate
at which consumers finish the tasks. To avoid unbounded growth, the task queue size is capped to a
specific size. This setting changes the value of that maximum number.
You generally don't need to change this setting. This setting also corresponds to the number of tasks
that the CLI is aware of that need to be run. This means that by default the CLI can only see 1000
tasks ahead. Until the S3 command knows the total number of tasks executed, the progress line
shows a total of .... Increasing this value means that the CLI can more quickly know the total number
of tasks needed, assuming that the queuing rate is quicker than the rate of task completion. The
tradeoff is that a larger max queue size requires more memory.
multipart_threshold
Specifies the size threshold the CLI uses for multipart transfers of individual files. The default value
is 8MB.
When uploading, downloading, or copying a file, the S3 commands switch to multipart operations if
the file exceeds this size. You can specify this value in one of two ways:
• The file size in bytes. For example, 1048576.
• The file size with a size suffix. You can use KB, MB, GB, or TB. For example: 10MB, 1GB.
Note
S3 can impose constraints on valid values that can be used for multipart operations. For
more information, see the S3 Multipart Upload documentation in the Amazon Simple
Storage Service Developer Guide.
multipart_chunksize
Specifies the chunk size that the CLI uses for multipart transfers of individual files. The default value
is 8MB, with a minimum of 5MB.
32
AWS Command Line Interface User Guide
Named Profiles
When a file transfer exceeds the multipart_threshold, the CLI divides the file into chunks of
this size. This value can specified using the same syntax as multipart_threshold, either as the
number of bytes as an integer, or by using a size and a suffix.
max_bandwidth
Specifies the maximum bandwidth that can be consumed for uploading and downloading data to
and from Amazon S3. The default is no limit.
This limits the maximum bandwidth that the S3 commands can use to transfer data to and from S3.
This value applies to only uploads and downloads; it doesn't apply to copies or deletes. The value is
expressed as bytes per second. The value can be specified as:
• An integer. For example, 1048576 sets the maximum bandwidth usage to 1 megabyte per second.
• An integer followed by a rate suffix. You can specify rate suffixes using: KB/s, MB/s, or GB/s. For
example: 300KB/s, 10MB/s.
In general, we recommend that you first try to lower bandwidth consumption by lowering
max_concurrent_requests. If that doesn't adequate limit bandwidth consumption to the
desired rate, then you can use the max_bandwidth setting can then be used to further limit
bandwidth consumption. This is because max_concurrent_requests controls how many
threads are currently running. If you instead first lower max_bandwidth but leave a high
max_concurrent_requests setting, it can result in threads having to wait unnecessarily, which
can lead to excess resource consumption and connection timeouts.
These settings are all set under a top level s3 key in the config file, as shown in the following example
for the development profile:
[profile development]
s3 =
max_concurrent_requests = 20
max_queue_size = 10000
multipart_threshold = 64MB
multipart_chunksize = 16MB
max_bandwidth = 50MB/s
use_accelerate_endpoint = true
addressing_style = path
Named Profiles
The AWS CLI supports using any of multiple named profiles that are stored in the config and
credentials files. You can configure additional profiles by using aws configure with the --profile
option, or by adding entries to the config and credentials files.
The following example shows a credentials file with two profiles. The first is used when you run a CLI
command with no profile. The second is used when you run a CLI command with the --profile user1
parameter.
[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
33
AWS Command Line Interface User Guide
Using Profiles with the AWS CLI
Each profile can specify different credentials—perhaps from different IAM users—and can also specify
different AWS Regions and output formats.
[default]
region=us-west-2
output=json
[profile user1]
region=us-east-1
output=text
Important
The credentials file uses a different naming format than the CLI config file for named
profiles. Include the prefix word "profile" only when configuring a named profile in the
config file. Do not use the word profile when creating an entry in the credentials file.
To use a named profile for multiple commands, you can avoid specifying the profile in every command
by setting the AWS_PROFILE environment variable at the command line.
$ export AWS_PROFILE=user1
Setting the environment variable changes the default profile until the end of your shell session, or
until you set the variable to a different value. You can make environment variables persistent across
future sessions by putting them in your shell's startup script. For more information, see Environment
Variables (p. 34).
Windows
Using set to set an environment variable changes the value used until the end of the current command
prompt session, or until you set the variable to a different value.
Using setx to set an environment variable changes the value in all command shells that you create after
running the command. It does not affect any command shell that is already running at the time you run
the command. Close and restart the command shell to see the effects of the change.
Environment Variables
Environment variables provide another way to specify configuration options and credentials, and can be
useful for scripting or temporarily setting a named profile as the default.
34
AWS Command Line Interface User Guide
Environment Variables
Precedence of options
• If you specify an option by using one of the environment variables described in this topic, it overrides
any value loaded from a profile in the configuration file.
• If you specify an option by using a parameter on the CLI command line, it overrides any value from
either the corresponding environment variable or a profile in the configuration file.
• AWS_ACCESS_KEY_ID – Specifies an AWS access key associated with an IAM user or role.
• AWS_SECRET_ACCESS_KEY – Specifies the secret key associated with the access key. This is essentially
the "password" for the access key.
• AWS_SESSION_TOKEN – Specifies the session token value that is required if you are using temporary
security credentials. For more information, see the Output section of the assume-role command in the
AWS CLI Command Reference.
• AWS_DEFAULT_REGION – Specifies the AWS Region (p. 23) to send the request to.
• AWS_DEFAULT_OUTPUT – Specifies the output format (p. 64) to use.
• AWS_PROFILE – Specifies the name of the CLI profile (p. 33) with the credentials and options to
use. This can be the name of a profile stored in a credentials or config file, or the value default
to use the default profile. If you specify this environment variable, it overrides the behavior of using
the profile named [default] in the configuration file.
• AWS_ROLE_SESSION_NAME – Specifies a name to associate with the role session. For more
information, see Specifying a Role Session Name for Easier Auditing (p. 45).
• AWS_CA_BUNDLE – Specifies the path to a certificate bundle to use for HTTPS certificate validation.
• AWS_SHARED_CREDENTIALS_FILE – Specifies the location of the file that the AWS CLI uses to store
access keys. The default path is ~/.aws/credentials).
• AWS_CONFIG_FILE – Specifies the location of the file that the AWS CLI uses to store configuration
profiles. The default path is ~/.aws/config).
The following example shows how you could configure environment variables for the default user. These
values would override any values found in a named profile, or instance metadata. Once set, you can
override these values by specifying a parameter on the CLI command line, or by changing or removing
the environment variable. For more information about precedence and how the AWS CLI determines
which credentials to use, see Configuration Settings and Precedence (p. 24).
$ export AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
$ export AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
$ export AWS_DEFAULT_REGION=us-west-2
Setting the environment variable changes the value used until the end of your shell session, or until
you set the variable to a different value. You can make the variables persistent across future sessions by
setting them in your shell's startup script.
35
AWS Command Line Interface User Guide
Command Line Options
Using set to set an environment variable changes the value used until the end of the current command
prompt session, or until you set the variable to a different value. Using setx to set an environment
variable changes the value used in both the current command prompt session and all command prompt
sessions that you create after running the command. It does not affect other command shells that are
already running at the time you run the command.
PowerShell
PS C:\> $Env:AWS_ACCESS_KEY_ID="AKIAIOSFODNN7EXAMPLE"
PS C:\> $Env:AWS_SECRET_ACCESS_KEY="wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
PS C:\> $Env:AWS_DEFAULT_REGION="us-west-2"
If you set an environment variable at the PowerShell prompt as shown in the previous examples, it
saves the value for only the duration of the current session. To make the environment variable setting
persistent across all PowerShell and Command Prompt sessions, store it by using the System application
in Control Panel. Alternatively, you can set the variable for all future PowerShell sessions by adding
it to your PowerShell profile. See the PowerShell documentation for more information about storing
environment variables or persisting them across sessions.
--profile <string>
Specifies the named profile (p. 33) to use for this command. To set up additional named profiles,
you can use the aws configure command with the --profile option.
--region <string>
Specifies which AWS Region to send this command's AWS request to. For a list of all of the Regions
that you can specify, see AWS Regions and Endpoints in the Amazon Web Services General Reference.
--output <string>
Specifies the output format to use for this command. You can specify any of the following values:
• json: The output is formatted as a JSON string.
• text: The output is formatted as multiple lines of tab-separated string values, which can be
useful if you want to pass the output to a text processor, like grep, sed, or awk.
• table: The output is formatted as a table using the characters +|- to form the cell borders. It
typically presents the information in a "human-friendly" format that is much easier to read than
the others, but not as programmatically useful.
--endpoint-url <string>
Specifies the URL to send the request to. For most commands, the AWS CLI automatically
determines the URL based on the selected service and the specified AWS Region. However, some
commands require that you specify an account-specific URL. You can also configure some AWS
services to host an endpoint directly within your private VPC, which might then need to be specified.
For a list of the standard service endpoints available in each Region, see AWS Regions and Endpoints
in the Amazon Web Services General Reference.
36
AWS Command Line Interface User Guide
Command Line Options
--debug
A boolean switch that specifies that you want to enable debug logging. This includes additional
diagnostic information about the operation of the command that can be useful when
troubleshooting why a command provides unexpected results.
--no-paginate
Specifies a JMESPath query to use in filtering the response data. For more information, see How to
Filter the Output with the --query Option (p. 68).
--version
A boolean switch that displays the current version of the AWS CLI program that is running.
--color <string>
Specifies support for color output. Valid values are on, off, and auto. The default value is auto.
--no-sign-request
A boolean switch that disables signing the HTTP requests to the AWS service endpoint. This prevents
credentials from being loaded.
--ca-bundle <string>
Specifies the maximum socket read time in seconds. If the value is set to 0, the socket read waits
indefinitely (is blocking) and doesn't timeout.
--cli-connect-timeout <integer>
Specifies the maximum socket connect time in seconds. If the value is set to 0, the socket connect
waits indefinitely (is blocking) and doesn't timeout.
When you provide one or more of these options as command line parameters, it overrides the default
configuration or any corresponding profile setting for that single command.
Each option that takes an argument requires a space or equals sign (=) separating the argument from
the option name. If the argument value is a string that contains a space, you must use quotation marks
around the argument.
Common uses for command line options include checking your resources in multiple AWS Regions, and
changing the output format for legibility or ease of use when scripting. For example, if you're not sure
which Region your instance is running in, you can run the describe-instances command against each
Region until you find it, as follows.
37
AWS Command Line Interface User Guide
Sourcing Credentials with an External Process
|| Reservations ||
|+-------------------------------------+------------------------------------+|
|| OwnerId | 012345678901 ||
|| ReservationId | r-abcdefgh ||
|+-------------------------------------+------------------------------------+|
||| Instances |||
||+------------------------+-----------------------------------------------+||
||| AmiLaunchIndex | 0 |||
||| Architecture | x86_64 |||
...
The argument types (for example, string, Boolean) for each command line option are described in detail
in Specifying Parameter Values (p. 54).
If you have a method to generate or lookup credentials that isn't directly supported by the AWS CLI, you
can configure the CLI to use it by configuring the credential_process setting in the config file.
For example, you might include an entry similar to the following in the config file:
[profile developer]
credential_process = "/opt/bin/awscreds-custom" "--username helen"
Syntax
To create this string in a way that is compatible with any operating system, follow these rules:
• The path and filename for the program to run must be surrounded by double-quotes.
• Parameters that include spaces must be surrounded by double-quotes.
• Do not include any environment variables in the strings. For example, you can't include $HOME or
%USERPROFILE%.
• Do not specify the home folder as ~. You must specify the full path.
38
AWS Command Line Interface User Guide
Instance Metadata
The AWS CLI runs the command as specified in the profile and then reads data from STDOUT. The
command you specify must generate JSON output on STDOUT that matches the following syntax:
{
"Version": 1,
"AccessKeyId": "an AWS access key",
"SecretAccessKey": "your AWS secret access key",
"SessionToken": "the AWS session token for temporary credentials",
"Expiration": "ISO8601 timestamp when the credentials expire"
}
As of this writing, the Version key must be set to 1. This might increment over time as the structure
evolves.
The Expiration key is an ISO8601 formatted timestamp. If the Expiration key is not present in
the tool's output, the CLI assumes that the credentials are long term credentials that do not refresh.
Otherwise the credentials are considered temporary credentials and are refreshed automatically by re-
running the credential_process command before they expire.
Note
The AWS CLI does not cache external process credentials the way it does assume-role
credentials. If caching is required, then you must implement it in the external process.
The external process can return a non-zero return code to indicate that an error occurred while retrieving
the credentials.
Instance Metadata
When you run the AWS CLI from within an Amazon EC2 instance, you can simplify providing credentials
to your commands. Each Amazon EC2 instance contains metadata that the AWS CLI can directly query
for temporary credentials. To provide these, create an AWS Identity and Access Management (IAM) role
that has access to the resources needed, and attach that role to the Amazon EC2 instance when you
launch it.
Launch the instance and check to see if the AWS CLI is already installed (it comes preinstalled on Amazon
Linux). If necessary, install the AWS CLI. You must still configure a default Region to avoid having to
specify it in every command.
To specify in a named profile that you want to use the credentials available in the hosting Amazon EC2
instance profile, specify the following line in the configuration file:
credential_source = Ec2InstanceMetadata
The following example shows how to assume the marketingadminrole role by referencing it in an
Amazon EC2 instance profile:
[profile marketingadmin]
role_arn = arn:aws:iam::123456789012:role/marketingadminrole
credential_source = Ec2InstanceMetadata
You can set the Region and default output format by running aws configure without specifying
credentials by pressing Enter twice to skip the first two prompts.
$ aws configure
AWS Access Key ID [None]: ENTER
AWS Secret Access Key [None]: ENTER
39
AWS Command Line Interface User Guide
Using an HTTP Proxy
When an IAM role is attached to the instance, the AWS CLI automatically and securely retrieves the
credentials from the instance metadata. For more information, see Granting Applications That Run on
Amazon EC2 Instances Access to AWS Resources in the IAM User Guide.
The following examples show how you can use either the explicit IP address of your proxy or a DNS name
that resolves to the IP address of your proxy. Either can be followed by a colon and the port number to
which queries should be sent.
$ export HTTP_PROXY=http://10.15.20.25:1234
$ export HTTP_PROXY=http://proxy.example.com:1234
$ export HTTPS_PROXY=http://10.15.20.25:5678
$ export HTTPS_PROXY=http://proxy.example.com:5678
Windows
Authenticating to a Proxy
The AWS CLI supports HTTP Basic authentication. Specify the user name and password in the proxy URL,
as follows.
$ export HTTP_PROXY=http://username:[email protected]:1234
$ export HTTPS_PROXY=http://username:[email protected]:5678
Windows
Note
The AWS CLI doesn't support NTLM proxies. If you use an NTLM or Kerberos protocol proxy, you
might be able to connect through an authentication proxy like Cntlm.
40
AWS Command Line Interface User Guide
Using a Proxy on Amazon EC2 Instances
$ export NO_PROXY=169.254.169.254
Windows
You can configure the AWS Command Line Interface (AWS CLI) to use an IAM role by defining a profile
for the role in the ~/.aws/credentials file.
The following example shows a role profile named marketingadmin. If you run commands with --
profile marketingadmin (or specify it with the AWS_PROFILE environment variable (p. 34)),
then the CLI uses the credentials defined in the profile user1 to assume the role with the Amazon
Resource Name (ARN) arn:aws:iam::123456789012:role/marketingadminrole. You can run any
operations that are allowed by the permissions assigned to that role.
[marketingadmin]
role_arn = arn:aws:iam::123456789012:role/marketingadminrole
source_profile = user1
You can then specify a source_profile that points to a separate named profile that contains IAM user
credentials with permission to use the role. In the previous example, the marketingadmin profile uses
the credentials in the user1 profile. When you specify that an AWS CLI command is to use the profile
marketingadmin, the CLI automatically looks up the credentials for the linked user1 profile and
uses them to request temporary credentials for the specified IAM role. The CLI uses the sts:AssumeRole
operation in the background to accomplish this. Those temporary credentials are then used to run the
requested CLI command. The specified role must have attached IAM permission policies that allow the
requested CLI command to run.
If you want to run a CLI command from within an Amazon EC2 instance or an Amazon ECS container, you
can use an IAM role attached to the instance profile or the container. If you specify no profile or set no
environment variables, that role is used directly. This enables you to avoid storing long-lived access keys
on your instances. You can also use those instance or container roles only to get credentials for another
role. To do this, you use credential_source (instead of source_profile) to specify how to find the
credentials. The credential_source attribute supports the following values:
The following example shows the same marketingadminrole role used by referencing an Amazon EC2
instance profile:
41
AWS Command Line Interface User Guide
Configuring and Using a Role
[profile marketingadmin]
role_arn = arn:aws:iam::123456789012:role/marketingadminrole
credential_source = Ec2InstanceMetadata
When you invoke a role, you have additional options that you can require, such as the use of multi-factor
authentication, an External ID (used by third party companies to access their clients' resources), and
specify unique role session names that can be more easily audited in AWS CloudTrail logs.
Sections
• Configuring and Using a Role (p. 42)
• Using Multi-Factor Authentication (p. 43)
• Cross-Account Roles & External ID (p. 44)
• Specifying a Role Session Name for Easier Auditing (p. 45)
• Assume Role With Web Identity (p. 45)
• Clearing Cached Credentials (p. 46)
You can create a new role in IAM with the permissions that you want users to assume by following the
procedure under Creating a Role to Delegate Permissions to an IAM User in the AWS Identity and Access
Management User Guide. If the role and the source profile's IAM user are in the same account, you can
enter your own account ID when configuring the role's trust relationship.
After creating the role, modify the trust relationship to allow the IAM user (or the users in the AWS
account) to assume it.
The following example shows a trust policy that you could attach to a role. This policy allows the role to
be assumed by any IAM user in the account 123456789012, if the administrator of that account explicitly
grants the sts:assumerole permission to the user.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::123456789012:root"
},
"Action": "sts:AssumeRole"
}
]
}
The trust policy doesn't actually grant permissions. The administrator of the account must delegate the
permission to assume the role to individual users by attaching a policy with the appropriate permissions.
The following example shows a policy that you can attach to an IAM user that allows the user to assume
only the marketingadminrole role. For more information about granting a user access to assume a
role, see Granting a User Permission to Switch Roles in the IAM User Guide.
42
AWS Command Line Interface User Guide
Using Multi-Factor Authentication
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "sts:AssumeRole",
"Resource": "arn:aws:iam::123456789012:role/marketingadminrole"
}
]
}
The IAM user doesn't need to have any additional permissions to run the CLI commands using the role
profile. Instead, the permissions to run the command come from those attached to the role. You attach
permission policies to the role to specify which actions can be performed against which AWS resources.
For more information about attaching permissions to a role (which works identically to an IAM user), see
Changing Permissions for an IAM User in the IAM User Guide.
Now that you have the role profile, role permissions, role trust relationship, and user permissions
properly configured, you can use the role at the command line by invoking the --profile option. For
example, the following command calls the Amazon S3 ls command using the permissions attached to
the marketingadmin role as defined by the example at the beginning of this topic.
To use the role for several calls, you can set the AWS_DEFAULT_PROFILE environment variable for the
current session from the command line. While that environment variable is defined, you don't have to
specify the --profile option on each command.
$ export AWS_PROFILE=marketingadmin
Windows
For more information on configuring IAM users and roles, see Users and Groups and Roles in the IAM
User Guide.
First, you can choose to modify the trust relationship on the IAM role to require MFA. This prevents
anyone from using the role without first authenticating by using MFA. For an example, see the
Condition line in the following example. This policy allows the IAM user named anika to assume the
role the policy is attached to, but only if she authenticates by using MFA.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": { "AWS": "arn:aws:iam::123456789012:user/anika" },
43
AWS Command Line Interface User Guide
Cross-Account Roles & External ID
"Action": "sts:AssumeRole",
"Condition": { "Bool": { "aws:multifactorAuthPresent": true } }
}
]
}
Next, add a line to the role profile that specifies the ARN of the user's MFA device. The following sample
config file entries show two role profiles that both use the access keys for the IAM user anika to
request temporary credentials for the role cli-role. The user anika has permissions to assume the
role, granted by the role's trust policy.
[profile role-without-mfa]
region = us-west-2
role_arn= arn:aws:iam::128716708097:role/cli-role
source_profile=cli-user
[profile role-with-mfa]
region = us-west-2
role_arn= arn:aws:iam::128716708097:role/cli-role
source_profile = cli-user
mfa_serial = arn:aws:iam::128716708097:mfa/cli-user
[profile anika]
region = us-west-2
output = json
The mfa_serial setting can take an ARN, as shown, or the serial number of a hardware MFA token.
The first profile, role-without-mfa, doesn't require MFA. However, because the previous example trust
policy attached to the role requires MFA, any attempt to run a command with this profile fails.
An error occurred (AccessDenied) when calling the AssumeRole operation: Access denied
The second profile entry, role-with-mfa, identifies an MFA device to use. When the user attempts to
run a CLI command with this profile, the CLI prompts the user to enter the one-time password (OTP)
provided by the MFA device. If the MFA authentication is succesful, the command then performs the
requested operation. The OTP is not displayed on the screen.
If you use an external ID to provide additional control over who can use a role across accounts, you must
also add the external_id parameter to the role profile. You typically use this only when the other
account is controlled by someone outside your company or organization.
44
AWS Command Line Interface User Guide
Specifying a Role Session Name for Easier Auditing
[profile crossaccountrole]
role_arn = arn:aws:iam::234567890123:role/SomeRole
source_profile = default
mfa_serial = arn:aws:iam::123456789012:mfa/saanvi
external_id = 123456
You can simplify this by specifying unique role session names when users assume a role. You do this by
adding a role_session_name parameter to each named profile in the config file that specifies a role.
The role_session_name value is passed to the AssumeRole operation and becomes part of the ARN
for the role session. It is also included in the AWS CloudTrail logs for all logged operations.
[profile namedsessionrole]
role_arn = arn:aws:iam::234567890123:role/SomeRole
source_profile = default
role_session_name = Session_Maria_Garcia
arn:aws:iam::234567890123:assumed-role/SomeRole/Session_Maria_Garcia
Also, all AWS CloudTrail logs include the role session name in the information captured for each
operation.
To retrieve and use temporary credentials using web identity federation, you can specify the following
configuration values in a shared profile:
Specifies the path to a file which contains an OAuth 2.0 access token or OpenID Connect ID token
that is provided by the identity provider. The AWS CLI loads this file and passes its content as the
WebIdentityToken argument of the AssumeRoleWithWebIdentity operation.
45
AWS Command Line Interface User Guide
Clearing Cached Credentials
Below is an example configuration for the minimal amount of configuration needed to configure an
assume role with web identity profile:
█ In ~/.aws/config
[profile web-identity]
role_arn=arn:aws:iam:123456789012:role/RoleNameToAssume
web_identity_token_file=/path/to/a/token
You can also provide this configuration by using environment variables (p. 34):
AWS_ROLE_ARN
Note
These environment variables currently only apply to the assume role with web identity provider and do
not apply to the general assume role provider configuration.
If your role's temporary credentials are revoked, they are not renewed automatically, and attempts to use
them fail. However, you can delete the cache to force the AWS CLI to retrieve new credentials.
$ rm -r ~/.aws/cli/cache
Windows
Command Completion
On Unix-like systems, the AWS CLI includes a command-completion feature that enables you to use
the Tab key to complete a partially typed command. On most systems, this feature isn't automatically
installed, so you need to configure it manually.
To configure command completion, you must have two pieces of information: the name of the shell
you're using and the location of the aws_completer script.
46
AWS Command Line Interface User Guide
Identify Your Shell
Amazon Linux
Command completion is automatically configured and enabled by default on Amazon EC2
instances that run Amazon Linux.
Sections
• Identify Your Shell (p. 47)
• Locate the AWS Completer (p. 47)
• Add the Completer's Folder to Your Path (p. 48)
• Enable Command Completion (p. 48)
• Test Command Completion (p. 49)
echo $SHELL – Show the shell's program file name. This usually matches the name of the in-use shell,
unless you launched a different shell after logging in.
$ echo $SHELL
/bin/bash
ps – Show the processes running for the current user. The shell will be one of them.
$ ps
PID TTY TIME CMD
2148 pts/1 00:00:00 bash
8756 pts/1 00:00:00 ps
Package Manager – Programs such as pip, yum, brew, and apt-get typically install the AWS completer
(or a symlink to it) to a standard path location. In this case, the which command can locate the
completer for you.
If you used pip without the --user command, you might see the following path.
$ which aws_completer
/usr/local/aws/bin/aws_completer
If you used the --user parameter on the pip install command, then the completer is typically found in
the local/bin folder under your $HOME folder.
$ which aws_completer
/home/username/.local/bin/aws_completer
Bundled Installer – If you used the bundled installer per the instructions in the previous section, the
AWS completer is located in the bin subfolder of the installation directory.
$ ls /usr/local/aws/bin
activate
47
AWS Command Line Interface User Guide
Add the Completer's Folder to Your Path
activate.csh
activate.fish
activate_this.py
aws
aws.cmd
aws_completer
...
If all else fails, you can use find to search your entire file system for the AWS completer.
1. Find your shell's profile script in your user folder. If you're not sure which shell you have, run echo
$SHELL.
$ ls -a ~
. .. .bash_logout .bash_profile .bashrc Desktop Documents Downloads
export PATH=/usr/local/aws/bin:$PATH
3. Reload the profile into the current session to put those changes into effect. Replace .bash_profile
with the name of the shell script you discovered in the first section.
$ source ~/.bash_profile
Add the command to ~/.bashrc to run it each time you open a new shell. Your ~/.bash_profile
should source ~/.bashrc to ensure that the command is run in login shells as well.
• tcsh – Complete for tcsh takes a word type and pattern to define the completion behavior.
48
AWS Command Line Interface User Guide
Test Command Completion
Add the command to ~/.tschrc to run it each time you open a new shell.
• zsh – source bin/aws_zsh_completer.sh.
% source /usr/local/aws/bin/aws_zsh_completer.sh
The AWS CLI uses bash compatibility autocompletion (bashcompinit) for zsh support. For more
details, see the top of aws_zsh_completer.sh.
Add the command to ~/.zshrc to run it each time you open a new shell.
$ aws sTAB
s3 ses sqs sts swf
s3api sns storagegateway support
49
AWS Command Line Interface User Guide
Getting Help
Topics
• Getting Help with the AWS CLI (p. 50)
• Command Structure in the AWS CLI (p. 54)
• Specifying Parameter Values for the AWS CLI (p. 54)
• Generate the CLI Skeleton and Input Parameters from a JSON Input File (p. 60)
• Controlling Command Output from the AWS CLI (p. 64)
• Using Shorthand Syntax with the AWS Command Line Interface (p. 73)
• Using AWS CLI Pagination Options (p. 74)
• Understanding Return Codes from the AWS CLI (p. 75)
For example, the following command displays help for the general AWS CLI options and the available
top-level commands.
$ aws help
The following command displays the available Amazon Elastic Compute Cloud (Amazon EC2) specific
commands.
The following example displays detailed help for the Amazon EC2 DescribeInstances operation. The
help includes descriptions of its input parameters, available filters, and what is included as output. It also
includes examples showing how to type common variations of the command.
Name
NAME
describe-instances -
50
AWS Command Line Interface User Guide
Getting Help
Description
DESCRIPTION
Describes one or more of your instances.
If you specify one or more instance IDs, Amazon EC2 returns information
for those instances. If you do not specify instance IDs, Amazon EC2
returns information for all relevant instances. If you specify an
instance ID that is not valid, an error is returned. If you specify an
instance that you do not own, it is not included in the returned
results.
...
Synopsis
The basic syntax for using the command and its options. If an option is shown in square brackets, it's
either optional, has a default value, or has an alternative option that you can use instead.
SYNOPSIS
describe-instances
[--dry-run | --no-dry-run]
[--instance-ids <value>]
[--filters <value>]
[--cli-input-json <value>]
[--starting-token <value>]
[--page-size <value>]
[--max-items <value>]
[--generate-cli-skeleton]
For example, describe-instances has a default behavior that describes all instances in the
current account and AWS Region. You can optionally specify a list of instance-ids to describe one
or more instances. dry-run is an optional boolean flag that doesn't take a value. To use a boolean
flag, specify either shown value, in this case --dry-run or --no-dry-run. Likewise, --generate-
cli-skeleton doesn't take a value. If there are conditions on an option's use, they are described in
the OPTIONS section, or shown in the examples.
Options
OPTIONS
--dry-run | --no-dry-run (boolean)
Checks whether you have the required permissions for the action,
without actually making the request, and provides an error response.
If you have the required permissions, the error response is DryRun-
Operation . Otherwise, it is UnauthorizedOperation .
--instance-ids (list)
One or more instance IDs.
Examples
Examples showing the usage of the command and its options. If no example is available for a
command or use case that you need, request one using the feedback link on this page, or in the AWS
CLI command reference on the help page for the command.
51
AWS Command Line Interface User Guide
Getting Help
EXAMPLES
To describe an Amazon EC2 instance
Command:
Command:
Command:
Output
Descriptions of each of the fields and data types included in the response from AWS.
For describe-instances, the output is a list of reservation objects, each of which contains several
fields and objects that contain information about the instances associated with it. This information
comes from the API documentation for the reservation data type used by Amazon EC2.
OUTPUT
Reservations -> (list)
One or more reservations.
(structure)
Describes a reservation.
(structure)
Describes a security group.
(structure)
Describes an instance.
52
AWS Command Line Interface User Guide
AWS CLI Documentation
When the output is rendered into JSON by the AWS CLI, it becomes an array of reservation objects,
similar to the following example.
{
"Reservations": [
{
"OwnerId": "012345678901",
"ReservationId": "r-4c58f8a0",
"Groups": [],
"RequesterId": "012345678901",
"Instances": [
{
"Monitoring": {
"State": "disabled"
},
"PublicDnsName": "ec2-52-74-16-12.us-west-2.compute.amazonaws.com",
"State": {
"Code": 16,
"Name": "running"
},
...
Each reservation object contains fields describing the reservation and an array of instance objects,
each with its own fields (for example, PublicDnsName) and objects (for example, State) that
describe it.
Windows users
You can pipe (|) the output of the help command to the more command to view the help file
one page at a time. Press the space bar or PgDn to view more of the document, and q to
quit.
API Documentation
All commands in the AWS CLI correspond to requests made to an AWS service's public API. Each service
with a public API has an API reference that can be found on the service's homepage on the AWS
53
AWS Command Line Interface User Guide
Command Structure
Documentation website. The content for an API reference varies based on how the API is constructed
and which protocol is used. Typically, an API reference contains detailed information about the actions
supported by the API, the data sent to and from the service, and any error conditions that the service can
report.
• Actions – Detailed information on each action and its parameters (including constraints on length or
content, and default values). It lists the errors that can occur for this action. Each action corresponds to
a subcommand in the AWS CLI.
• Data Types – Detailed information about structures that a command might require as a parameter or
return in response to a request.
• Common Parameters – Detailed information about the parameters that are shared by all of action for
the service.
• Common Errors – Detailed information about errors that can be returned by any of the service's
actions.
The name and availability of each section can vary depending on the service.
Service-specific CLIs
Some services have a separate CLI that dates from before a single AWS CLI was created to work
with all services. These service-specific CLIs have separate documentation that is linked from
the service's documentation page. Documentation for service-specific CLIs does not apply to the
AWS CLI.
Parameters can take various types of input values, such as numbers, strings, lists, maps, and JSON
structures. What is supported is dependent upon the command and subcommand you specify.
Strings without any space characters can be surrounded with quotation marks or not. However, you must
use quotation marks around strings that include one or more space characters. Use single quotation
54
AWS Command Line Interface User Guide
Common Parameter Types
marks (' ') in Linux, macOS, Unix, or PowerShell. Use double quotation marks (" ") in the Windows
command prompt, as shown in the following examples.
Optionally, you can optionally separate the parameter name from the value with an equals sign (=)
instead of a space. This is typically necessary only if the value of the parameter starts with a hyphen.
Topics
• Common Parameter Types (p. 55)
• Using JSON for Parameters (p. 56)
• Using Quotation Marks with Strings (p. 58)
• Loading Parameters from a File (p. 58)
The help for each subcommand describes its function, options, output, and examples. The options
section includes the name and description of each option with the option's parameter type in
parentheses.
String – String parameters can contain alphanumeric characters, symbols, and white space from the
ASCII character set. Strings that contain white space must be surrounded by quotation marks. We
recommend that you don't use symbols or white space other than the standard space character because
it can cause unexpected results.
Some string parameters can accept binary data from a file. See Binary Files (p. 60) for an example.
Timestamp – Timestamps are formatted according to the ISO 8601 standard. These are sometimes
referred to as "DateTime" or "Date" parameters.
55
AWS Command Line Interface User Guide
Using JSON for Parameters
List – One or more strings separated by spaces. If any of the string items contain a space, you must put
quotation marks around that item.
Boolean – Binary flag that turns an option on or off. For example, ec2 describe-spot-price-
history has a Boolean --dry-run parameter that, when specified, validates the query with the service
without actually running the query.
The output indicates whether the command was well formed. This command also includes a --no-dry-
run version of the parameter that you can use to explicitly indicate that the command should be run
normally. Including it isn't necessary because this is the default behavior.
Blob – Binary object. Blob parameters take a path to a local file that contains the binary data. The
path should not contain any protocol identifier, such as http:// or file://. The specified path is
interpreted as being relative to the current working directory.
For example, the --body parameter for aws s3api put-object is a blob.
Map – A set of key-value pairs specified in JSON or by using the CLI's shorthand syntax (p. 73). The
following JSON example reads an item from an Amazon DynamoDB table named my-table with a map
parameter, --key. The parameter specifies the primary key named id with a number value of 1 in a
nested JSON structure.
Alternatively, you can specify the equivalent list of filters as a JSON array. Square brackets are used to
create an array of JSON objects separated by commas. Each object is a comma-separated list of key-
value pairs (in this example, "Name" and "Values" are both keys).
56
AWS Command Line Interface User Guide
Using JSON for Parameters
The value to the right of the "Values" key is itself an array. This is required, even if the array contains only
one value string.
[
{
"Name": "instance-type",
"Values": ["t2.micro", "m1.medium"]
},
{
"Name": "availability-zone",
"Values": ["us-west-2c"]
}
]
The outermost brackets, however, are required only if more than one filter is specified. A single filter
version of the previous command, formatted in JSON, looks like this.
For some operations, you must format the data as JSON. For example, to pass parameters to the --
block-device-mappings parameter in the ec2 run-instances command, you need to format the
block device information as JSON.
This example shows the JSON to specify a single 20 GiB Amazon Elastic Block Store (Amazon EBS) device
to be mapped at /dev/sdb on the launching instance.
{
"DeviceName": "/dev/sdb",
"Ebs": {
"VolumeSize": 20,
"DeleteOnTermination": false,
"VolumeType": "standard"
}
}
To attach multiple devices, list the objects in an array, as shown in the next example.
[
{
"DeviceName": "/dev/sdb",
"Ebs": {
"VolumeSize": 20,
"DeleteOnTermination": false,
"VolumeType": "standard"
}
},
{
"DeviceName": "/dev/sdc",
"Ebs": {
"VolumeSize": 10,
"DeleteOnTermination": true,
"VolumeType": "standard"
}
}
]
You can enter the JSON directly on the command line (see Using Quotation Marks with
Strings (p. 58)), or save it to a file that is referenced from the command line (see Loading Parameters
from a File (p. 58)).
57
AWS Command Line Interface User Guide
Using Quotation Marks with Strings
When passing in large blocks of data, you might find it easier to first save the JSON to a file and then
reference it from the command line. JSON data in a file is easier to read, edit, and share with others. This
technique is described in a later section.
For more information about JSON, see JSON.org, Wikipedia's JSON entry, and RFC4627 - The
application/json Media Type for JSON.
Use single quotation marks (' ') to enclose the JSON data structure, as in the following example:
PowerShell
PowerShell requires single quotation marks (' ') to enclose the JSON data structure, as well as a
backslash (\) to escape each double quotation mark (") within the JSON structure, as in the following
example:
The Windows command prompt requires double quotation marks (" ") to enclose the JSON data
structure. You must then escape (precede with a backslash [ \ ] character) each double quotation
mark (") within the JSON data structure itself, as in the following example:
If the value of a parameter is itself a JSON document, escape the quotation marks on the embedded
JSON document. For example, the attribute parameter for aws sqs create-queue can take a
RedrivePolicy key. The --attributes parameter takes a JSON document, which in turn contains
RedrivePolicy, which also takes a JSON document as its value. The inner JSON embedded in the outer
JSON must be escaped.
58
AWS Command Line Interface User Guide
Loading Parameters from a File
from a file. Whether a file is required or optional, the file must be encoded correctly to be understood by
the AWS CLI. The file's encoding must match the reading system's default locale. This can be determined
by using the Python locale.getpreferredencoding() method.
Note
By default, Windows PowerShell outputs text as UTF-16, which conflicts with the UTF-8
encoding used by many Linux systems. We recommend that you use -Encoding ascii with
your PowerShell Out-File commands to ensure the resulting file can be read by the AWS CLI.
Sometimes it's convenient to load a parameter value from a file instead of trying to type it all as a
command line parameter value, such as when the parameter is a complex JSON string. To specify a file
that contains the value, specify a file URL in the following format:
file://complete/path/to/file
The first two slash '/' characters are part of the specification. If the required path begins with a '/', then
the result is three slash characters: file:///folder/file.
The URL provides the path to the file that contains the actual parameter content.
Note
This behaviour is disabled automatically for parameters that already expect a URL, such as
parameter that identifies a AWS CloudFormation template URL.
You can also disable this behaviour yourself by adding the following line to your CLI
configuration file:
cli_follow_urlparam = false
The file paths in the following examples are interpreted to be relative to the current working directory.
Windows
The file:// prefix option supports Unix-style expansions, including "~/", "./", and "../". On Windows,
the "~/" expression expands to your user directory, stored in the %USERPROFILE% environment variable.
For example, on Windows 10 you would typically have a user directory under C:\Users\User Name\.
JSON documents that are embedded as the value of another JSON document must still be escaped.
attributes.json
{
"RedrivePolicy": "{\"deadLetterTargetArn\":\"arn:aws:sqs:us-
west-2:0123456789012:deadletter\", \"maxReceiveCount\":\"5\"}"
}
59
AWS Command Line Interface User Guide
Generate the CLI Skeleton
Binary Files
For commands that take binary data as a parameter, specify that the data is binary content by using the
fileb:// prefix. Commands that accept binary data include:
The following example generates a binary 256-bit AES key using a Linux command line tool, and then
provides it to Amazon S3 to encrypt an uploaded file server-side.
Remote Files
The AWS CLI also supports loading parameters from a file hosted on the internet with an http:// or
https:// URL. The following example references a file stored in an Amazon S3 bucket. This allows you
to access parameter files from any computer, but it does require that the container is publicly accessible.
The preceding example assumes that the file filename.json contains the following JSON data.
[
{
"DeviceName": "/dev/sdb",
"Ebs": {
"VolumeSize": 20,
"DeleteOnTermination": false,
"VolumeType": "standard"
}
}
]
For another example referencing a file containing more complex JSON-formatted parameters, see Attach
an IAM Managed Policy to an IAM User (p. 95).
60
AWS Command Line Interface User Guide
Generate the CLI Skeleton
Those same commands helpfully provide the --generate-cli-skeleton to generate a file with all
of the parameters that you can edit and fill in. Then you can run the command with the --cli-input-
json parameter and point to the filled-in file.
Important
There are several AWS CLI commands that don't map directly to individual AWS API operations,
such as the aws s3 commands. Such commands don't support either the --generate-cli-
skeleton or --cli-input-json parameters that are discussed on this page. If you have
any question about whether a specific command supports these parameters, run the following
command, replacing the service and command names with the ones you're interested in:
The output includes a Synopsis section that shows the parameters that the specified command
supports.
The --generate-cli-skeleton parameter causes the command not to run, but instead to generate
and display a parameter template that you can customize and then use as input on a later command. The
generated template includes all of the parameters supported by the command.
Because the AWS CLI is essentially a "wrapper" around the service's API, the skeleton file expects you
to reference all parameters by their underlying API parameter name, which is likely different from the
AWS CLI parameter name. For example, an AWS CLI parameter called user-name might map to the
AWS service's API parameter named UserName (note the altered capitalization and missing dash). We
recommend that you use the --generate-cli-skeleton option to generate the template with the
"correct" parameter names to avoid errors. You can also reference the API Reference Guide for the service
to see the expected parameter names. You can delete any parameters from the template that are not
required and for which you don't want to supply a value.
For example, if you run the following command, it generates the parameter template for the Amazon
Elastic Compute Cloud (Amazon EC2) command run-instances.
61
AWS Command Line Interface User Guide
Generate the CLI Skeleton
"VolumeType": "",
"Iops": 0,
"Encrypted": true
},
"NoDevice": ""
}
],
"Monitoring": {
"Enabled": true
},
"SubnetId": "",
"DisableApiTermination": true,
"InstanceInitiatedShutdownBehavior": "",
"PrivateIpAddress": "",
"ClientToken": "",
"AdditionalInfo": "",
"NetworkInterfaces": [
{
"NetworkInterfaceId": "",
"DeviceIndex": 0,
"SubnetId": "",
"Description": "",
"PrivateIpAddress": "",
"Groups": [
""
],
"DeleteOnTermination": true,
"PrivateIpAddresses": [
{
"PrivateIpAddress": "",
"Primary": true
}
],
"SecondaryPrivateIpAddressCount": 0,
"AssociatePublicIpAddress": true
}
],
"IamInstanceProfile": {
"Arn": "",
"Name": ""
},
"EbsOptimized": true
}
1. Run the command with the --generate-cli-skeleton parameter and direct the output to a file
to save it.
2. Open the parameter skeleton file in your text editor and remove any of the parameters that you
don't need. For example, you might strip it down to the following. Be sure that the file is still valid
JSON after you remove the elements you don't need.
{
"DryRun": true,
"ImageId": "",
"KeyName": "",
"SecurityGroups": [
""
],
"InstanceType": "",
62
AWS Command Line Interface User Guide
Generate the CLI Skeleton
"Monitoring": {
"Enabled": true
}
}
In this example, we leave the DryRun parameter set to true to use EC2's dry run feature, which lets
you safely test the command without actually creating or modifying any resources.
3. Fill in the remaining values with values appropriate for your scenario. In this example, we provide
the instance type, key name, security group and identifier of the AMI to use. This example assumes
the default region. The AMI ami-dfc39aef is a 64-bit Amazon Linux image hosted in the us-
west-2 region. If you use a different region, you must find the correct AMI ID to use.
{
"DryRun": true,
"ImageId": "ami-dfc39aef",
"KeyName": "mykey",
"SecurityGroups": [
"my-sg"
],
"InstanceType": "t2.micro",
"Monitoring": {
"Enabled": true
}
}
4. Run the command with the completed parameters by passing the JSON file to the --cli-input-
json parameter using the file:// prefix. The AWS CLI interprets the path to be relative to your
current working directory, so the following example which displays only the file name with no path
is looked for the file directly in the current working directory.
The dry run error indicates that the JSON is formed correctly and the parameter values are valid. If
any other issues are reported in the output, fix them and repeat the above step until the "Request
would have succeeded" message is displayed.
5. Now you can set the DryRun parameter to false to disable dry run.
{
"DryRun": false,
"ImageId": "ami-dfc39aef",
"KeyName": "mykey",
"SecurityGroups": [
"my-sg"
],
"InstanceType": "t2.micro",
"Monitoring": {
"Enabled": true
}
}
6. Now when you run the command, run-instances actually launches an EC2 instance and displays
the details generated by the successful launch.
63
AWS Command Line Interface User Guide
Controlling Command Output
"Groups": [],
"Instances": [
...
Topics
• How to Select the Output Format (p. 64)
• JSON Output Format (p. 65)
• Text Output Format (p. 65)
• Table Output Format (p. 67)
• How to Filter the Output with the --query Option (p. 68)
• JSON (json)
• Tab-delimited text (text)
• ASCII-formatted table (table)
As explained in the configuration (p. 22) topic, you can specify the output format in three ways:
• Using the output option in a named profile in the config file. The following example sets the default
output format to text.
[default]
output=text
• Using the AWS_DEFAULT_OUTPUT environment variable. The following output sets the format to
table for the commands in this command-line session until the variable is changed or the session
ends. Using this environment variable overrides any value set in the config file.
$ export AWS_DEFAULT_OUTPUT="table"
• Using the --output option on the command line. The following example sets the output of only this
one command to json. Using this option on the command overrides any currently set environment
variable or the value in the config file.
AWS CLI precedence rules (p. 24) apply. For example, using the AWS_DEFAULT_OUTPUT environment
variable overrides any value set in the config file, and a value passed to an AWS CLI command with --
output overrides any value set in the environment variable or in the config file.
The json option is best for handling the output programmatically via various languages or jq (a
command-line JSON processor).
64
AWS Command Line Interface User Guide
JSON Output Format
The text format works well with traditional Unix text processing tools, such as sed, grep, and awk, as
well as in PowerShell scripts.
The results in any format can be customized and filtered by using the --query parameter. For more
information, see How to Filter the Output with the --query Option (p. 68).
If you need more advanced features that might not be possible with --query, you can check out
jq, a command line JSON processor. You can download it and find the official tutorial at http://
stedolan.github.io/jq/.
The text output format follows the basic structure shown below. The columns are sorted alphabetically
by the corresponding key names of the underlying JSON object.
Important
We strongly recommend that if you specify text output, you also always use the --query option
to ensure consistent behavior. This is because the text format alphabetically orders output
columns by the key name of the underlying JSON object, and similar resources might not have
the same key names. For example, the JSON representation of a Linux-based EC2 instance might
have elements that are not present in the JSON representation of a Windows-based instance, or
vice versa. Also, resources might have key-value elements added or removed in future updates,
altering the column ordering. This is where --query augments the functionality of the text
output to provide you with complete control over the output format. In the following example,
the command specifies which elements to display and defines the ordering of the columns with
the list notation [key1, key2, ...]. This gives you full confidence that the correct key
values are always displayed in the expected column. Finally, notice how the AWS CLI outputs
None as values for keys that don't exist.
65
AWS Command Line Interface User Guide
Text Output Format
The following example show how you can use grep and awk with the text output from the aws ec2
describe-instances command. The first command displays the Availability Zone, current state, and
the instance ID of each instance in text output. The second command processes that output to display
only the instance IDs of all running instances in the us-west-2a Availability Zone.
The following example goes a step further and shows not only how to filter the output, but how to use
that output to automate changing instance types for each stopped instance.
The text output can also be useful in PowerShell. Because the columns in text output is tab-delimited,
it's easily split into an array by using PowerShell's `t delimiter. The following command displays the
value of the third column (InstanceId) if the first column (AvailabilityZone) matches the string
us-west-2a.
Please note that although the previous example does show how to use the --query parameter to
parse the underlying JSON objects and pull out the desired column, PowerShell has its own ability to
handle JSON that you can use if cross-platform compatibility is not a concern. Instead of dealing with
the output as text, as most command shells require, PowerShell lets you use the ConvertFrom-JSON
cmdlet to produce a hierarchically structured object. You can then directly access the desired member
from that object.
66
AWS Command Line Interface User Guide
Table Output Format
Tip
If you output text, and filter the output to a single field using the --query parameter, the output
is a single line of tab separated values. To get each value onto a separate line, you can put the
output field in brackets as shown in the following examples:
67
AWS Command Line Interface User Guide
How to Filter the Output with the --query Option
|+------------------+---------------------------+-------+----------------+---------
+----------------+--------------+|
|| us-west-2a | 2013-09-18T20:26:15.000Z | 8 | snap-708e8348 | in-use |
vol-2e410a47 | standard ||
|+------------------+---------------------------+-------+----------------+---------
+----------------+--------------+|
||| Attachments
|||
||+---------------------------+------------------------+-------------+--------------
+------------+----------------+||
||| AttachTime | DeleteOnTermination | Device | InstanceId |
State | VolumeId |||
||+---------------------------+------------------------+-------------+--------------
+------------+----------------+||
||| 2013-09-18T20:26:16.000Z | True | /dev/sda1 | i-4b41a37c |
attached | vol-2e410a47 |||
||+---------------------------+------------------------+-------------+--------------
+------------+----------------+||
You can combine the --query option with the table format to display a set of elements preselected
from the raw output. Notice the output differences between dictionary and list notations: column names
are alphabetically ordered in the first example, and unnamed columns are ordered as defined by the user
in the second example. For more information about the --query option, see How to Filter the Output
with the --query Option (p. 68).
• If you specify --output text, the output is paginated before the --query filter is
applied and the AWS CLI runs the query once on each page of the output. This can result in
unexpected extra output, especially if your filter specifies an array element using something
like [0], because the output then includes the first matching element on each page.
• If you specify --output json, the output is completely processed and converted into a
JSON structure before the --query filter is applied. The AWS CLI runs the query only once
against the entire output.
68
AWS Command Line Interface User Guide
How to Filter the Output with the --query Option
To work around the extra output that can be produced if you use --output text, you can
specify --no-paginate. This causes the filter to apply only to the complete set of results,
but it does remove any pagination, so could result in long output. You could also use other
command line tools such as head or tail to additionally filter the output to only the values
you want.
To demonstrate how --query works, we first start with the default JSON output below, which describes
two Amazon Elastic Block Store (Amazon EBS) volumes attached to separate Amazon EC2 instances.
We can choose to display only the first volume from the Volumes list by using the following command
that indexes the first volume in the array.
69
AWS Command Line Interface User Guide
How to Filter the Output with the --query Option
"VolumeId": "vol-e11a5288",
"State": "attached",
"DeleteOnTermination": true,
"Device": "/dev/sda1"
}
],
"VolumeType": "standard",
"VolumeId": "vol-e11a5288",
"State": "in-use",
"SnapshotId": "snap-f23ec1c8",
"CreateTime": "2013-09-17T00:55:03.000Z",
"Size": 30
}
In the next example, we use the wildcard notation [*] to iterate over all of the volumes in
the list and also filter out three elements from each: VolumeId, AvailabilityZone, and
Size. The dictionary notation requires that you provide an alias for each JSON key, like this:
{Alias1:JSONKey1,Alias2:JSONKey2}. A dictionary is inherently unordered, so the ordering of the
key-aliases within a structure might be inconsistent.
Using dictionary notation, you can also chain keys together, like key1.key2[0].key3, to filter
elements deeply nested within the structure. The following example demonstrates this with the
Attachments[0].InstanceId key, aliased to simply InstanceId.
You can also filter multiple elements using list notation: [key1, key2]. This formats all filtered
attributes into a single ordered list per object, regardless of type.
70
AWS Command Line Interface User Guide
How to Filter the Output with the --query Option
[
"vol-e11a5288",
"i-a071c394",
"us-west-2a",
30
],
[
"vol-2e410a47",
"i-4b41a37c",
"us-west-2a",
8
]
]
To filter results by the value of a specific field, use the JMESPath "?" operator. The following example
query outputs only volumes in the us-west-2a Availability Zone.
Note
When specifying a literal value such as "us-west-2" above in a JMESPath query expression, you
must surround the value in backticks (` `) for it to be read properly.
Here are some additional examples that illustrate how you can get only the details you want from the
output of your commands.
The following example lists Amazon EC2 volumes. The service produces a list of all in-use volumes in the
us-west-2a Availability Zone. The --query parameter further limits the output to only those volumes
with a Size value that is larger than 50, and shows only the specified fields with user-defined names.
The following example retrieves a list of images that meet several criteria. It then uses the --query
parameter to sort the output by CreationDate, selecting only the most recent. It then displays the
ImageId of that one image.
The following example uses the --query parameter to find a specific item in a list and then extracts
information from that item. The example lists all of the availability zones associated with the
specified service endpoint. It extracts the item from the ServiceDetails list that has the specified
ServiceName, then outputs the AvailabilityZones field from that selected item.
71
AWS Command Line Interface User Guide
How to Filter the Output with the --query Option
[
[
"us-east-1a",
"us-east-1b",
"us-east-1c",
"us-east-1d",
"us-east-1e",
"us-east-1f"
]
]
The --query parameter also enables you to count items in the output. The following example displays
the number of available volumes that are more than 1000 IOPS.
The following example shows how to list all of your snapshots that were created after a specified date,
including only a few of the available fields in the output.
The following example lists the five most recent AMIs that you created, sorted from most recent to
oldest.
72
AWS Command Line Interface User Guide
Shorthand Syntax
This following example shows only the InstanceId for any unhealthy instances in the specified
AutoScaling Group.
Combined with the three output formats that are explained in more detail in the following sections, the
--query option is a powerful tool you can use to customize the content and style of outputs.
For more examples and the full spec of JMESPath, the underlying JSON-processing library, see http://
jmespath.org/specification.html.
Structure Parameters
The shorthand syntax in the AWS CLI makes it easier for users to input parameters that are flat (non-
nested structures). The format is a comma-separated list of key-value pairs.
--option key1=value1,key2=value2,key3=value3
PowerShell
--option "key1=value1,key2=value2,key3=value3"
--option '{"key1":"value1","key2":"value2","key3":"value3"}'
There must be no white space between each comma-separated key-value pair. Here is an example of the
Amazon DynamoDBupdate-table command with the --provisioned-throughput option specified
in shorthand.
73
AWS Command Line Interface User Guide
List Parameters
List Parameters
You can specify Input parameters in a list form in two ways: JSON or shorthand. The AWS CLI shorthand
syntax is designed to make it easier to pass in lists with number, string, or non-nested structures.
The basic format is shown here, where values in the list are separated by a single space.
--option '[value1,value2,value3]'
As previously mentioned, you can specify a list of numbers, a list of strings, or a list of non-nested
structures in shorthand. The following is an example of the stop-instances command for Amazon
Elastic Compute Cloud (Amazon EC2), where the input parameter (list of strings) for the --instance-
ids option is specified in shorthand.
The following example shows the Amazon EC2 create-tags command, which takes a list of non-
nested structures for the --tags option. The --resources option specifies the ID of the instance to
tag.
This is equivalent to the following example, formatted in JSON. The JSON parameter is written in
multiple lines for readability.
By default, the AWS CLI uses a page size of 1000 and retrieves all available items. For example, if you
run aws s3api list-objects on an Amazon S3 bucket that contains 3,500 objects, the CLI makes
four calls to Amazon S3, handling the service-specific pagination logic for you in the background and
returning all 3,500 objects in the final output.
If you see issues when running list commands on a large number of resources, the default page size of
1000 might be too high. This can cause calls to AWS services to exceed the maximum allowed time and
74
AWS Command Line Interface User Guide
Return Codes
generate a "timed out" error. You can use the --page-size option to specify that the AWS CLI request
a smaller number of items from each call to the AWS service. The CLI still retrieves the full list, but
performs a larger number of service API calls in the background and retrieves a smaller number of items
with each call. This gives the individual calls a better chance of succeeding without a timeout. Changing
the page size doesn't affect the output; it affects only the number of API calls that need to be made to
generate the output.
To include fewer items at a time in the AWS CLI output, use the --max-items option. The AWS CLI still
handles pagination with the service as described above, but prints out only the number of items at a
time that you specify.
If the number of items output (--max-items) is fewer than the total number of items returned by the
underlying API calls, the output includes a NextToken that you can pass to a subsequent command to
retrieve the next set of items. The following example shows how to use the NextToken value returned
by the previous example, and enables you to retrieve the second 100 items.
Note
The parameter --starting-token cannot be null or empty. If the previous command does not
return a NextToken value, then there are no more items to return and you do not need to call
the command again.
The specified AWS service might not return items in the same order each time you call. If you specify
different values for --page-size and --max-items, you can get unexpected results with missing or
duplicated items. To prevent this, use the same number for --page-size and --max-items to sync the
AWS CLI's pagination with the pagination of the underlying service. You can also retrieve the whole list
and perform any necessary paging operations locally.
Linux/Unix/Mac systems
$ echo $?
Windows PowerShell
75
AWS Command Line Interface User Guide
Return Codes
The following are the return code values that can be returned at the end of running an AWS Command
Line Interface (AWS CLI) command.
Code
Meaning
0 The command completed successfully. There were no errors generated by either the AWS CLI or by
the AWS service to which the request was sent.
• The command entered on the command line couldn't be parsed. Parsing failures can be caused
by, but aren't limited to, missing required subcommands or arguments, or using unknown
commands or arguments.
Limited to S3 commands.
255The command failed. There were errors generated by either the AWS CLI or by the AWS service to
which the request was sent.
To learn more details about a failure, run the command with the --debug switch. This produces a
detailed report of the steps the AWS CLI uses to process the command, and what the result of each step
was.
76
AWS Command Line Interface User Guide
DynamoDB
For a complete reference of all the available commands for each service, see the AWS CLI Command
Reference, or use the built-in command line help. For more information, see Getting Help with the AWS
CLI (p. 50).
Topics
• Using Amazon DynamoDB with the AWS CLI (p. 77)
• Using Amazon EC2 with the AWS CLI (p. 79)
• Using Amazon S3 Glacier with the AWS CLI (p. 90)
• Using AWS Identity and Access Management from the AWS CLI (p. 94)
• Using Amazon S3 with the AWS CLI (p. 97)
• Using Amazon SNS with the AWS CLI (p. 103)
• Using Amazon SWF with the AWS CLI (p. 105)
To list the AWS CLI commands for DynamoDB, use the following command.
Before you run any commands, set your default credentials. For more information, see Configuring the
AWS CLI (p. 22).
The command line format consists of an Amazon DynamoDB API name, followed by the parameters for
that API. The AWS CLI supports the CLI shorthand syntax (p. 73) for the parameter values, as well as full
JSON.
77
AWS Command Line Interface User Guide
DynamoDB
--provisioned-throughput ReadCapacityUnits=1,WriteCapacityUnits=1
You can add new lines to the table with commands similar to those shown in the following example.
These examples use a combination of shorthand syntax and JSON.
It can be difficult to compose valid JSON in a single-line command. To make this easier, the AWS CLI
can read JSON files. For example, consider the following JSON snippet, which is stored in a file named
expression-attributes.json.
{
":v1": {"S": "No One You Know"},
":v2": {"S": "Call Me Today"}
}
You can use that file to issue a query request using the AWS CLI. In the following example, the content
of the expression-attributes.json file is used for the --expression-attribute-values
parameter.
78
AWS Command Line Interface User Guide
Amazon EC2
}
],
"ScannedCount": 1,
"ConsumedCapacity": null
}
For more information about using the AWS CLI with DynamoDB, see DynamoDB in the AWS CLI
Command Reference.
In addition to DynamoDB, you can use the AWS CLI with DynamoDB Local. DynamoDB Local is a small
client-side database and server that mimics the DynamoDB service. DynamoDB Local enables you to
write applications that use the DynamoDB API, without actually manipulating any tables or data in the
DynamoDB web service. Instead, all of the API actions are rerouted to a local database. This lets you save
on provisioned throughput, data storage, and data transfer fees.
For more information about DynamoDB Local and how to use it with the AWS CLI, see the following
sections of the Amazon DynamoDB Developer Guide:
• DynamoDB Local
• Using the AWS CLI with DynamoDB Local
Before you run any commands, set your default credentials. For more information, see Configuring the
AWS CLI (p. 22).
This topic shows examples of AWS CLI commands that perform common tasks for Amazon EC2.
Topics
• Create, Display, and Delete Amazon EC2 Key Pairs (p. 79)
• Create, Configure, and Delete Security Groups for Amazon EC2 (p. 81)
• Launch, List, and Terminate Amazon EC2 Instances (p. 85)
You must provide the key pair to Amazon EC2 when you create the instance, and then use that key pair
to authenticate when you connect to the instance.
Note
The following examples assume that you have already configured your default
credentials (p. 79).
Topics
• Creating a Key Pair (p. 80)
• Displaying Your Key Pair (p. 80)
• Deleting Your Key Pair (p. 81)
79
AWS Command Line Interface User Guide
Amazon EC2 Key Pairs
For PowerShell, the > file redirection defaults to UTF-8 encoding, which cannot be used with some
SSH clients. So, you must convert the output by piping it to the out-file command and explicitly set
the encoding to ascii.
-----BEGIN RSA PRIVATE KEY-----
EXAMPLEKEYKCAQEAy7WZhaDsrA1W3mRlQtvhwyORRX8gnxgDAfRt/gx42kWXsT4rXE/b5CpSgie/
vBoU7jLxx92pNHoFnByP+Dc21eyyz6CvjTmWA0JwfWiW5/akH7iO5dSrvC7dQkW2duV5QuUdE0QW
Z/aNxMniGQE6XAgfwlnXVBwrerrQo+ZWQeqiUwwMkuEbLeJFLhMCvYURpUMSC1oehm449ilx9X1F
G50TCFeOzfl8dqqCP6GzbPaIjiU19xX/azOR9V+tpUOzEL+wmXnZt3/nHPQ5xvD2OJH67km6SuPW
oPzev/D8V+x4+bHthfSjR9Y7DvQFjfBVwHXigBdtZcU2/wei8D/HYwIDAQABAoIBAGZ1kaEvnrqu
/uler7vgIn5m7lN5LKw4hJLAIW6tUT/fzvtcHK0SkbQCQXuriHmQ2MQyJX/0kn2NfjLV/ufGxbL1
mb5qwMGUnEpJaZD6QSSs3kICLwWUYUiGfc0uiSbmJoap/GTLU0W5Mfcv36PaBUNy5p53V6G7hXb2
bahyWyJNfjLe4M86yd2YK3V2CmK+X/BOsShnJ36+hjrXPPWmV3N9zEmCdJjA+K15DYmhm/tJWSD9
81oGk9TopEp7CkIfatEATyyZiVqoRq6k64iuM9JkA3OzdXzMQexXVJ1TLZVEH0E7bhlY9d8O1ozR
oQs/FiZNAx2iijCWyv0lpjE73+kCgYEA9mZtyhkHkFDpwrSM1APaL8oNAbbjwEy7Z5Mqfql+lIp1
YkriL0DbLXlvRAH+yHPRit2hHOjtUNZh4Axv+cpg09qbUI3+43eEy24B7G/Uh+GTfbjsXsOxQx/x
p9otyVwc7hsQ5TA5PZb+mvkJ5OBEKzet9XcKwONBYELGhnEPe7cCgYEA06Vgov6YHleHui9kHuws
ayav0elc5zkxjF9nfHFJRry21R1trw2Vdpn+9g481URrpzWVOEihvm+xTtmaZlSp//lkq75XDwnU
WA8gkn6O3QE3fq2yN98BURsAKdJfJ5RL1HvGQvTe10HLYYXpJnEkHv+Unl2ajLivWUt5pbBrKbUC
gYBjbO+OZk0sCcpZ29sbzjYjpIddErySIyRX5gV2uNQwAjLdp9PfN295yQ+BxMBXiIycWVQiw0bH
oMo7yykABY7Ozd5wQewBQ4AdSlWSX4nGDtsiFxWiI5sKuAAeOCbTosy1s8w8fxoJ5Tz1sdoxNeGs
Arq6Wv/G16zQuAE9zK9vvwKBgF+09VI/1wJBirsDGz9whVWfFPrTkJNvJZzYt69qezxlsjgFKshy
WBhd4xHZtmCqpBPlAymEjr/TOlbxyARmXMnIOWIAnNXMGB4KGSyl1mzSVAoQ+fqR+cJ3d0dyPl1j
jjb0Ed/NY8frlNDxAVHE8BSkdsx2f6ELEyBKJSRr9snRAoGAMrTwYneXzvTskF/S5Fyu0iOegLDa
NWUH38v/nDCgEpIXD5Hn3qAEcju1IjmbwlvtW+nY2jVhv7UGd8MjwUTNGItdb6nsYqM2asrnF3qS
VRkAKKKYeGjkpUfVTrW0YFjXkfcrR/V+QFL5OndHAKJXjW7a4ejJLncTzmZSpYzwApc=
-----END RSA PRIVATE KEY-----
Your private key isn't stored in AWS and can be retrieved only when it's created. You can't recover it later.
Instead, if you lose the private key, you must create a new key pair.
If you're connecting to your instance from a Linux computer, we recommend that you use the following
command to set the permissions of your private key file so that only you can read it.
The fingerprint is an SHA1 hash taken from a DER-encoded copy of the private key. This value is captured
when the key pair is created, and is stored in AWS with the public key. You can view the fingerprint in the
Amazon EC2 console or by running the AWS CLI command aws ec2 describe-key-pairs.
80
AWS Command Line Interface User Guide
Amazon EC2 Security Groups
For more information about keys and fingerprints, see Amazon EC2 Key Pairs in the Amazon EC2 User
Guide for Linux Instances.
You can use the AWS Command Line Interface (AWS CLI) to create a security group, add rules to existing
security groups, and delete security groups.
Note
The examples shown below assume that you have already configured your default
credentials (p. 79).
Topics
• Creating a Security Group (p. 81)
• Adding Rules to Your Security Group (p. 82)
• Deleting Your Security Group (p. 84)
EC2-VPC
The following example shows how to create a security group for a specified VPC.
$ aws ec2 create-security-group --group-name my-sg --description "My security group" --vpc-
id vpc-1a2b3c4d
{
"GroupId": "sg-903004f8"
81
AWS Command Line Interface User Guide
Amazon EC2 Security Groups
To view the initial information for a security group, run the describe-security-groups command. You can
reference an EC2-VPC security group only by its vpc-id, not its name.
EC2-Classic
The following example shows how to create a security group for EC2-Classic.
To view the initial information for my-sg, run the describe-security-groups command. For an EC2-Classic
security group, you can reference it by its name.
82
AWS Command Line Interface User Guide
Amazon EC2 Security Groups
For example, if you're launching a Windows instance, you typically add a rule to allow inbound traffic
on TCP port 3389 to support Remote Desktop Protocol (RDP). If you're launching a Linux instance, you
typically add a rule to allow inbound traffic on TCP port 22 to support SSH connections.
EC2-VPC
The following example shows how to add a rule for RDP (TCP port 3389) to an EC2-VPC security group
with the ID sg-903004f8. This example assumes the client computer has an address somewhere in the
CIDR range 203.0.113.0/24.
You can start by confirming that your public address shows as included in the CIDR range
203.0.113.0/24.
$ curl https://checkip.amazonaws.com
203.0.113.57
With that information confirmed, you can add the range to your security group by running the
authorize-security-group-ingress command.
The following command adds another rule to enable SSH to instances in the same security group.
To view the changes to the security group, run the describe-security-groups command.
83
AWS Command Line Interface User Guide
Amazon EC2 Security Groups
"IpProtocol": "tcp",
"IpRanges": [
{
"CidrIp": "203.0.113.0/24"
}
]
"UserIdGroupPairs": [],
"FromPort": 22
}
],
"GroupName": "my-sg",
"OwnerId": "123456789012",
"GroupId": "sg-903004f8"
}
]
}
EC2-Classic
The following command adds a rule for RDP to the EC2-Classic security group named my-sg.
The following command adds another rule for SSH to the same security group.
To view the changes to your security group, run the describe-security-groups command.
84
AWS Command Line Interface User Guide
EC2 Instances
Note
You can't delete a security group if it's currently attached to an environment.
EC2-VPC
The following command deletes an EC2-VPC security group.
EC2-Classic
The following command deletes the EC2-Classic security group named my-sg.
If you launch an instance that isn't within the AWS Free Tier, you are billed after you launch the instance
and charged for the time that the instance is running, even if it remains idle.
Note
The following examples assume that you have already configured your default
credentials (p. 79).
Topics
• Launching an Instance (p. 85)
• Adding a Block Device to Your Instance (p. 88)
• Adding a Tag to Your Instance (p. 89)
• Connecting to Your Instance (p. 89)
• Listing Your Instances (p. 89)
• Terminating an Instance (p. 90)
Launching an Instance
To launch an Amazon EC2 instance using the AMI you selected, use the run-instances command. You can
launch the instance into a virtual private cloud (VPC), or if your account supports it, or into EC2-Classic.
Initially, your instance appears in the pending state, but changes to the running state after a few
minutes.
EC2-VPC
The following example shows how to launch a t2.micro instance in the specified subnet of a VPC.
Replace the italicized parameter values with your own.
85
AWS Command Line Interface User Guide
EC2 Instances
{
"GroupName": "my-sg",
"GroupId": "sg-903004f8"
}
],
"Instances": [
{
"Monitoring": {
"State": "disabled"
},
"PublicDnsName": null,
"Platform": "windows",
"State": {
"Code": 0,
"Name": "pending"
},
"EbsOptimized": false,
"LaunchTime": "2013-07-19T02:42:39.000Z",
"PrivateIpAddress": "10.0.1.114",
"ProductCodes": [],
"VpcId": "vpc-1a2b3c4d",
"InstanceId": "i-5203422c",
"ImageId": "ami-173d747e",
"PrivateDnsName": ip-10-0-1-114.ec2.internal,
"KeyName": "MyKeyPair",
"SecurityGroups": [
{
"GroupName": "my-sg",
"GroupId": "sg-903004f8"
}
],
"ClientToken": null,
"SubnetId": "subnet-6e7f829e",
"InstanceType": "t2.micro",
"NetworkInterfaces": [
{
"Status": "in-use",
"SourceDestCheck": true,
"VpcId": "vpc-1a2b3c4d",
"Description": "Primary network interface",
"NetworkInterfaceId": "eni-a7edb1c9",
"PrivateIpAddresses": [
{
"PrivateDnsName": "ip-10-0-1-114.ec2.internal",
"Primary": true,
"PrivateIpAddress": "10.0.1.114"
}
],
"PrivateDnsName": "ip-10-0-1-114.ec2.internal",
"Attachment": {
"Status": "attached",
"DeviceIndex": 0,
"DeleteOnTermination": true,
"AttachmentId": "eni-attach-52193138",
"AttachTime": "2013-07-19T02:42:39.000Z"
},
"Groups": [
{
"GroupName": "my-sg",
"GroupId": "sg-903004f8"
}
],
"SubnetId": "subnet-6e7f829e",
"OwnerId": "123456789012",
"PrivateIpAddress": "10.0.1.114"
}
86
AWS Command Line Interface User Guide
EC2 Instances
],
"SourceDestCheck": true,
"Placement": {
"Tenancy": "default",
"GroupName": null,
"AvailabilityZone": "us-west-2b"
},
"Hypervisor": "xen",
"BlockDeviceMappings": [
{
"DeviceName": "/dev/sda1",
"Ebs": {
"Status": "attached",
"DeleteOnTermination": true,
"VolumeId": "vol-877166c8",
"AttachTime": "2013-07-19T02:42:39.000Z"
}
}
],
"Architecture": "x86_64",
"StateReason": {
"Message": "pending",
"Code": "pending"
},
"RootDeviceName": "/dev/sda1",
"VirtualizationType": "hvm",
"RootDeviceType": "ebs",
"Tags": [
{
"Value": "MyInstance",
"Key": "Name"
}
],
"AmiLaunchIndex": 0
}
]
}
EC2-Classic
If your account supports it, you can use the following command to launch a t1.micro instance in EC2-
Classic. Replace the italicized parameter values with your own.
87
AWS Command Line Interface User Guide
EC2 Instances
},
"EbsOptimized": false,
"LaunchTime": "2013-07-19T02:42:39.000Z",
"ProductCodes": [],
"InstanceId": "i-5203422c",
"ImageId": "ami-173d747e",
"PrivateDnsName": null,
"KeyName": "MyKeyPair",
"SecurityGroups": [
{
"GroupName": "my-sg",
"GroupId": "sg-903004f8"
}
],
"ClientToken": null,
"InstanceType": "t1.micro",
"NetworkInterfaces": [],
"Placement": {
"Tenancy": "default",
"GroupName": null,
"AvailabilityZone": "us-west-2b"
},
"Hypervisor": "xen",
"BlockDeviceMappings": [
{
"DeviceName": "/dev/sda1",
"Ebs": {
"Status": "attached",
"DeleteOnTermination": true,
"VolumeId": "vol-877166c8",
"AttachTime": "2013-07-19T02:42:39.000Z"
}
}
],
"Architecture": "x86_64",
"StateReason": {
"Message": "pending",
"Code": "pending"
},
"RootDeviceName": "/dev/sda1",
"VirtualizationType": "hvm",
"RootDeviceType": "ebs",
"Tags": [
{
"Value": "MyInstance",
"Key": "Name"
}
],
"AmiLaunchIndex": 0
}
]
}
To add a block device to your instance, specify the --block-device-mappings option when you use
run-instances.
The following example parameter provisions a standard Amazon EBS volume that is 20 GB in size, and
maps it to your instance using the identifier /dev/sdf.
88
AWS Command Line Interface User Guide
EC2 Instances
--block-device-mappings "[{\"DeviceName\":\"/dev/sdf\",\"Ebs\":{\"VolumeSize\":20,
\"DeleteOnTermination\":false}}]"
The following example adds an Amazon EBS volume, mapped to /dev/sdf, based on an existing
snapshot. A snapshot represents an image that is loaded onto the volume for you. When you specify a
snapshot, you don't have to specify a volume size; it will be large enough to hold your image. However, if
you do specify a size, it must be greater than or equal to the size of the snapshot.
--block-device-mappings "[{\"DeviceName\":\"/dev/sdf\",\"Ebs\":{\"SnapshotId\":\"snap-
a1b2c3d4\"}}]"
The following example adds two volumes to your instance. The number of volumes available to your
instance depends on its instance type.
--block-device-mappings "[{\"DeviceName\":\"/dev/sdf\",\"VirtualName\":\"ephemeral0\"},
{\"DeviceName\":\"/dev/sdg\",\"VirtualName\":\"ephemeral1\"}]"
The following example creates the mapping (/dev/sdj), but doesn't provision a volume for the
instance.
--block-device-mappings "[{\"DeviceName\":\"/dev/sdj\",\"NoDevice\":\"\"}]"
For more information, see Block Device Mapping in the Amazon EC2 User Guide for Linux Instances.
The following example shows how to add a tag with the key name "Name and the value "MyInstance" to
the specified instance, by using the create-tags command.
The following command filters the list to only your t2.micro instances and outputs only the
InstanceId values for each match.
89
AWS Command Line Interface User Guide
Glacier
The following command lists any of your instances that have the tag Name=MyInstance.
The following command lists your instances that were launched using any of the following AMIs: ami-
x0123456, ami-y0123456, and ami-z0123456.
Terminating an Instance
Terminating an instance deletes it. You can't reconnect to an instance after you've terminated it.
As soon as the state of the instance changes to shutting-down or terminated, you stop incurring
charges for that instance. If you want to reconnect to an instance later, use stop-instances instead of
terminate-instances. For more information, see Terminate Your Instance in the Amazon EC2 User
Guide for Linux Instances.
When you finish with an instance, you can use the command terminate-instances to delete it.
This topic shows examples of AWS CLI commands that perform common tasks for S3 Glacier. The
examples demonstrate how to use the AWS CLI to upload a large file to Glacier by splitting it into smaller
parts and uploading them from the command line.
Before you run any commands, set your default credentials. For more information, see Configuring the
AWS CLI (p. 22).
Note
This tutorial uses several command line tools that typically come preinstalled on Unix-like
operating systems, including Linux and OS X. Windows users can use the same tools by
installing Cygwin and running the commands from the Cygwin terminal. Windows native
commands and utilities that perform the same functions are noted where available.
90
AWS Command Line Interface User Guide
Creating an Amazon S3 Glacier Vault
Topics
• Creating an Amazon S3 Glacier Vault (p. 91)
• Preparing a File for Uploading (p. 91)
• Initiating a Multipart Upload and Upload Files (p. 91)
• Completing the Upload (p. 92)
Note
All S3 Glacier commands require an account ID parameter. Use the hyphen character (--
account-id -) to use the current account.
dd is a utility that copies a number of bytes from an input file to an output file. The previous example
uses the system device file /dev/urandom as a source of random data. fsutil performs a similar
function in Windows.
Windows
Note
HJ-Split is a free file splitter for Windows and many other platforms.
91
AWS Command Line Interface User Guide
Completing the Upload
S3 Glacier requires the size of each part in bytes (1 MiB in this example), your vault name, and an account
ID to configure the multipart upload. The AWS CLI outputs an upload ID when the operation is complete.
Save the upload ID to a shell variable for later use.
$ UPLOADID="19gaRezEXAMPLES6Ry5YYdqthHOC_kGRCT03L9yetr220UmPtBYKk-
OssZtLqyFu7sY1_lR7vgFuJV6NtcV5zpsJ"
Windows
Next, use the upload-multipart-part command to upload each of the three parts.
Note
The previous example uses the dollar sign ($) to reference the contents of the UPLOADID shell
variable on Linux. On the Windows command line, use a percent sign on either side of the
variable name (for example, %UPLOADID%).
You must specify the byte range of each part when you upload it so that Glacier can reassemble it in
the correct order. Each piece is 1,048,576 bytes, so the first piece occupies bytes 0-1048575, the second
1048576-2097151, and the third 2097152-3145727.
To calculate a tree hash, you must split the file into 1 MiB parts and calculate a binary SHA-256 hash of
each piece. Then you split the list of hashes into pairs, combine the two binary hashes in each pair, and
92
AWS Command Line Interface User Guide
Completing the Upload
take hashes of the results. Repeat this process until there is only one hash left. If there is an odd number
of hashes at any level, promote it to the next level without modifying it.
The key to calculating a tree hash correctly when using command line utilities is to store each hash in
binary format and convert to hexadecimal only at the last step. Combining or hashing the hexadecimal
version of any hash in the tree will cause an incorrect result.
Note
Windows users can use the type command in place of cat. OpenSSL is available for Windows at
OpenSSL.org.
1. If you haven't already, split the original file into 1 MiB parts.
3. Combine the first two hashes and take the binary hash of the result.
4. Combine the parent hash of chunks aa and ab with the hash of chunk ac and hash the result, this
time outputting hexadecimal. Store the result in a shell variable.
Finally, complete the upload with the complete-multipart-upload command. This command takes
the original file's size in bytes, the final tree hash value in hexadecimal, and your account ID and vault
name.
You can also check the status of the vault using the describe-vault command.
93
AWS Command Line Interface User Guide
IAM
"VaultARN": "arn:aws:glacier:us-west-2:123456789012:vaults/myvault",
"LastInventoryDate": "2018-12-07T00:26:19.028Z",
"NumberOfArchives": 1,
"CreationDate": "2018-12-06T21:23:45.708Z",
"VaultName": "myvault"
}
Note
Vault status is updated about once per day. See Working with Vaults for more information.
Now it's safe to remove the chunk and hash files that you created.
$ rm chunk* hash*
For more information on multipart uploads, see Uploading Large Archives in Parts and Computing
Checksums in the Amazon S3 Glacier Developer Guide.
This topic shows examples of AWS CLI commands that perform common tasks for IAM.
Before you run any commands, set your default credentials. For more information, see Configuring the
AWS CLI (p. 22).
Topics
• Creating IAM Users and Groups (p. 94)
• Attach an IAM Managed Policy to an IAM User (p. 95)
• Set an Initial Password for an IAM User (p. 96)
• Create an Access Key for an IAM User (p. 97)
Before you run any commands, set your default credentials. For more information, see Configuring the
AWS CLI (p. 22).
94
AWS Command Line Interface User Guide
Attach an IAM Managed Policy to an IAM User
"CreateDate": "2018-12-14T03:03:52.834Z",
"GroupId": "AGPAJNUJ2W4IJVEXAMPLE",
"Arn": "arn:aws:iam::123456789012:group/MyIamGroup",
"Path": "/"
}
}
4. To verify that the MyIamGroup group contains the MyUser, use the get-group command.
Before you run any commands, set your default credentials. For more information, see Configuring the
AWS CLI (p. 22).
1. Determine the ARN of the policy to attach. The following command uses list-policies to find
the ARN of the policy with the name PowerUserAccess. It then stores that ARN in an environment
variable.
95
AWS Command Line Interface User Guide
Set an Initial Password for an IAM User
2. To attach the policy, use the attach-user-policy command, and reference the environment
variable that holds the policy ARN.
3. Verify that the policy is attached to the user by running the list-attached-user-policies
command.
Additional Resources
For more information, see Access Management Resources. This topic provides links to an overview of
permissions and policies, and links to examples of policies for accessing Amazon S3, Amazon EC2, and
other services.
Before you run any commands, set your default credentials. For more information, see Configuring the
AWS CLI (p. 22).
The following command uses create-login-profile to set an initial password on the specified user. When
the user signs in for the first time, the user is required to change the password to something that only
the user knows.
You can use the update-login-profile command to change the password for an IAM user.
96
AWS Command Line Interface User Guide
Create an Access Key for an IAM User
Before you run any commands, set your default credentials. For more information, see Configuring the
AWS CLI (p. 22).
You can use the create-access-key command to create an access key for an IAM user. An access key is
a set of security credentials that consists of an access key ID and a secret key.
An IAM user can create only two access keys at one time. If you try to create a third set, the command
returns a LimitExceeded error.
Use the delete-access-key command to delete an access key for an IAM user. Specify which access
key to delete by using the access key ID.
Before you run any commands, set your default credentials. For more information, see Configuring the
AWS CLI (p. 22).
The AWS CLI provides two tiers of commands for accessing Amazon S3:
• The s3 tier consists of high-level commands that simplify performing common tasks, such as creating,
manipulating, and deleting objects and buckets.
• The s3api tier behaves identically to other AWS services by exposing direct access to all Amazon S3
API operations. It enables you to carry out advanced operations that might not be possible with the
following tier's high-level commands alone.
To get a list of all of the commands available in each tier, use the help argument with the aws s3api or
aws s3 commands.
$ aws s3 help
97
AWS Command Line Interface User Guide
High-Level (s3) Commands
Note
The AWS CLI supports copying, moving, and syncing from Amazon S3 to Amazon S3 using the
server-side COPY operation provided by Amazon S3. This means that your files are kept in the
cloud, and are not downloaded to the client machine, then back up to Amazon S3.
When operations such as these can be performed completely in the cloud, only the bandwidth
necessary for the HTTP request and response is used.
For examples of Amazon S3 usage, see the following topics in this section.
Topics
• Using High-Level (s3) Commands with the AWS CLI (p. 98)
• Using API-Level (s3api) Commands with the AWS CLI (p. 102)
Before you run any commands, set your default credentials. For more information, see Configuring the
AWS CLI (p. 22).
Managing Buckets
High-level aws s3 commands support common bucket operations, such as creating, listing, and deleting
buckets.
Creating a Bucket
Use the s3 mb command to create a bucket. Bucket names must be globally unique and should be DNS
compliant. Bucket names can contain lowercase letters, numbers, hyphens, and periods. Bucket names
can start and end only with a letter or number, and cannot contain a period next to a hyphen or another
period.
$ aws s3 mb s3://bucket-name
$ aws s3 ls
2018-12-11 17:08:50 my-bucket
2018-12-14 14:55:44 my-bucket2
The following command lists all objects and folders (referred to in S3 as 'prefixes') in a bucket.
$ aws s3 ls s3://bucket-name
PRE path/
2018-12-04 19:05:48 3 MyFile1.txt
The previous output shows that under the prefix path/ there exists one file named MyFile1.txt.
You can filter the output to a specific prefix by including it in the command. The following command lists
the objects in bucket-name/path (that is, objects in bucket-name filtered by the prefix path/).
98
AWS Command Line Interface User Guide
High-Level (s3) Commands
$ aws s3 ls s3://bucket-name/path/
2018-12-06 18:59:32 3 MyFile2.txt
Deleting a Bucket
To remove a bucket, use the s3 rb command.
$ aws s3 rb s3://bucket-name
By default, the bucket must be empty for the operation to succeed. To remove a non-empty bucket, you
need to include the --force option.
The following example deletes all objects and subfolders in the bucket and then removes the bucket.
Note
If you're using a versioned bucket that contains previously deleted—but retained—objects, this
command does not allow you to remove the bucket. You must first remove all of the content.
Managing Objects
The high-level aws s3 commands make it convenient to manage Amazon S3 objects. The object
commands include s3 cp, s3 ls, s3 mv, s3 rm, and s3 sync.
The cp, ls, mv, and rm commands work similarly to their Unix counterparts and enable you to work
seamlessly across your local directories and Amazon S3 buckets. The sync command synchronizes the
contents of a bucket and a directory, or two buckets.
Note
All high-level commands that involve uploading objects into an Amazon S3 bucket (s3 cp, s3
mv, and s3 sync) automatically perform a multipart upload when the object is large.
Failed uploads can't be resumed when using these commands. If the multipart upload fails due
to a timeout or is manually canceled by pressing Ctrl+C, the AWS CLI cleans up any files created
and aborts the upload. This process can take several minutes.
If the process is interrupted by a kill command or system failure, the in-progress multipart
upload remains in Amazon S3 and must be cleaned up manually in the AWS Management
Console or with the s3api abort-multipart-upload command.
The cp, mv, and sync commands include a --grants option that you can use to grant permissions on
the object to specified users or groups. Set the --grants option to a list of permissions using following
syntax.
--grants Permission=Grantee_Type=Grantee_ID
[Permission=Grantee_Type=Grantee_ID ...]
• Permission – Specifies the granted permissions, and can be set to read, readacl, writeacl, or
full.
• Grantee_Type – Specifies how to identify the grantee, and can be set to uri, emailaddress, or id.
• Grantee_ID – Specifies the grantee based on Grantee_Type.
• uri – The group's URI. For more information, see Who Is a Grantee?
• emailaddress – The account's email address.
• id – The account's canonical ID.
99
AWS Command Line Interface User Guide
High-Level (s3) Commands
The following example copies an object into a bucket. It grants read permissions on the object to
everyone and full permissions (read, readacl, and writeacl) to the account associated with
[email protected].
You can also specify a nondefault storage class (REDUCED_REDUNDANCY or STANDARD_IA) for objects
that you upload to Amazon S3. To do this, use the --storage-class option.
The s3 sync command uses the following syntax. Possible source-target combinations are:
The following example synchronizes the contents of an Amazon S3 folder named path in my-bucket with
the current working directory. s3 sync updates any files that have a different size or modified time than
files with the same name at the destination. The output displays specific operations performed during
the sync. Notice that the operation recursively synchronizes the subdirectory MySubdirectory and its
contents with s3://my-bucket/path/MySubdirectory.
Typically, s3 sync only copies missing or outdated files or objects between the source and target.
However, you can also supply the --delete option to remove files or objects from the target that are
not present in the source.
The following example, which extends the previous one, shows how this works.
100
AWS Command Line Interface User Guide
High-Level (s3) Commands
delete: MySubdirectory\MyFile3.txt
You can use the --exclude and --include options to specify rules that filter the files or objects
to copy during the sync operation. By default, all items in a specified folder are included in the sync.
Therefore, --include is needed only when you have to specify exceptions to the --exclude option
(that is, --include effectively means "don't exclude"). The options apply in the order that's specified, as
shown in the following example.
The --exclude and --include options also filter files or objects to be deleted during an s3 sync
operation that includes the --delete option. In this case, the parameter string must specify files to
exclude from, or include for, deletion in the context of the target directory or bucket. The following
shows an example.
Assume local directory and s3://my-bucket/path currently in sync and each contains 3 files:
MyFile1.txt
MyFile2.rtf
MyFile88.txt
'''
// Delete local .txt files
$ rm *.txt
// Sync with delete, excluding files that match a pattern. MyFile88.txt is deleted, while
remote MyFile1.txt is not.
$ aws s3 sync . s3://my-bucket/path --delete --exclude "my-bucket/path/MyFile?.txt"
delete: s3://my-bucket/path/MyFile88.txt
'''
// Delete MyFile2.rtf
$ aws s3 rm s3://my-bucket/path/MyFile2.rtf
The s3 sync command also accepts an --acl option, by which you may set the access permissions for
files copied to Amazon S3. The --acl option accepts private, public-read, and public-read-
write values.
101
AWS Command Line Interface User Guide
API Level (s3api) Commands
As previously mentioned, the s3 command set includes cp, mv, ls, and rm, and they work in similar ways
to their Unix counterparts. The following are some examples.
// Delete s3://my-bucket/path/MyFile.txt
$ aws s3 rm s3://my-bucket/path/MyFile.txt
When you use the --recursive option on a directory or folder with cp, mv, or rm, the command
walks the directory tree, including all subdirectories. These commands also accept the --exclude, --
include, and --acl options as the sync command does.
This topic provides examples that demonstrate how to use the lower-level commands that map to
the Amazon S3 API. In addition, you can find examples for each S3 API in the s3api section of the CLI
Reference Guide.
Before you run any commands, set your default credentials. For more information, see Configuring the
AWS CLI (p. 22).
The following example shows how to grant full control to two AWS users ([email protected] and
[email protected]) and read permission to everyone. The identifier for "everyone" comes from a
special URI that you pass as a parameter.
102
AWS Command Line Interface User Guide
Amazon SNS
For details about how to construct the ACLs, see PUT Bucket acl in the Amazon Simple Storage Service
API Reference. The s3api ACL commands in the CLI, such as put-bucket-acl, use the same shorthand
argument notation.
In the following example, the AWS user [email protected] is granted full control over the log files, and
all users have read access to them. Notice that the put-bucket-acl command is also required to grant
the Amazon S3 log delivery system (specified by a URI) the permissions needed to read and write the
logs to the bucket.
The file logging.json in the previous command has the following content.
{
"LoggingEnabled": {
"TargetBucket": "MyBucket",
"TargetPrefix": "MyBucketLogs/",
"TargetGrants": [
{
"Grantee": {
"Type": "AmazonCustomerByEmail",
"EmailAddress": "[email protected]"
},
"Permission": "FULL_CONTROL"
},
{
"Grantee": {
"Type": "Group",
"URI": "http://acs.amazonaws.com/groups/global/AllUsers"
},
"Permission": "READ"
}
]
}
}
Before you run any commands, set your default credentials. For more information, see Configuring the
AWS CLI (p. 22).
This topic shows examples of CLI commands that perform common tasks for Amazon SNS.
Topics
103
AWS Command Line Interface User Guide
Create a Topic
Create a Topic
To create a topic, use the create-topic command and specify the name to assign to the topic.
Make a note of the response's TopicArn, which you use later to publish a message.
Subscribe to a Topic
To subscribe to a topic, use the subscribe command.
The following example specifies the email protocol and an email address for the notification-
endpoint.
AWS immediately sends a confirmation message by email to the address you specified in the subscribe
command. The email message has the following text.
After the recipient clicks the Confirm subscription link, the recipient's browser displays a notification
message with information similar to the following.
Subscription confirmed!
Publish to a Topic
To send a message to all subscribers of a topic, use the publish command.
104
AWS Command Line Interface User Guide
Unsubscribe from a Topic
The following example sends the message "Hello World!" to all subscribers of the specified topic.
In this example, AWS sends an email message with the text "Hello World!" to [email protected].
To verify that you successfully unsubscribed, use the list-subscriptions command to confirm that the ARN
no longer appears in the list.
Delete a Topic
To delete a topic, run the delete-topic command.
To verify that AWS successfully deleted the topic, use the list-topics command to confirm that the topic
no longer appears in the list.
To list the AWS CLI commands for Amazon SWF, use the following command.
Before you run any commands, set your default credentials. For more information, see Configuring the
AWS CLI (p. 22).
This topic shows examples of CLI commands that perform common tasks for Amazon SWF.
Topics
• List of Amazon SWF Commands by Category (p. 106)
• Working with Amazon SWF Domains Using the AWS CLI (p. 108)
105
AWS Command Line Interface User Guide
List of Amazon SWF Commands
This section lists the reference topics for Amazon SWF commands in the AWS CLI, grouped by functional
category.
For an alphabetic list of commands, see the Amazon SWF section of the AWS CLI Command Reference, or
use the following command.
You can also get help for an individual command, by placing the help directive after the command
name. The following shows an example.
Topics
• Commands Related to Activities (p. 106)
• Commands Related to Deciders (p. 106)
• Commands Related to Workflow Executions (p. 107)
• Commands Related to Administration (p. 107)
• Visibility Commands (p. 107)
• poll-for-activity-task
• respond-activity-task-completed
• respond-activity-task-failed
• respond-activity-task-canceled
• record-activity-task-heartbeat
• poll-for-decision-task
• respond-decision-task-completed
106
AWS Command Line Interface User Guide
List of Amazon SWF Commands
• request-cancel-workflow-execution
• start-workflow-execution
• signal-workflow-execution
• terminate-workflow-execution
Activity Management
• register-activity-type
• deprecate-activity-type
Workflow Management
• register-workflow-type
• deprecate-workflow-type
Domain Management
• register-domain
• deprecate-domain
For more information and examples of these domain management commands, see Working with
Amazon SWF Domains Using the AWS CLI (p. 108).
Visibility Commands
Although you can perform visibility actions from the Amazon SWF console, you can use the commands in
this section to build your own console or administrative tools.
Activity Visibility
• list-activity-types
• describe-activity-type
Workflow Visibility
• list-workflow-types
107
AWS Command Line Interface User Guide
Working with Amazon SWF Domains
• describe-workflow-type
Domain Visibility
• list-domains
• describe-domain
For more information and examples of these domain visibility commands, see Working with Amazon
SWF Domains Using the AWS CLI (p. 108).
Topics
• List Your Domains (p. 108)
• Get Information about a Domain (p. 109)
• Register a Domain (p. 109)
• Deprecating a Domain (p. 110)
• See Also (p. 110)
108
AWS Command Line Interface User Guide
Working with Amazon SWF Domains
{
"status": "REGISTERED",
"name": "ExampleDomain"
},
{
"status": "REGISTERED",
"name": "mytest"
}
]
}
Note
For an example of using DEPRECATED, see Deprecating a Domain (p. 110).
Register a Domain
To register new domains, use swf register-domain.
There are two required parameters, --name, which takes the domain name to register, and --
workflow-execution-retention-period-in-days, which takes an integer to specify the number
of days to retain workflow execution data on this domain, up to a maximum period of 90 days (for more
information, see the Amazon SWF FAQ).
If you specify zero (0) for this value, the retention period is automatically set at the maximum duration.
Otherwise, workflow execution data isn't retained after the specified number of days have passed. The
following example shows how to register a new domain.
The command doesn't return any output, but you can use swf list-domains or swf describe-
domain to see the new domain. For example:
109
AWS Command Line Interface User Guide
Working with Amazon SWF Domains
Deprecating a Domain
To deprecate a domain (you can still see it, but cannot create new workflow executions or register types
on it), use swf deprecate-domain. It has a sole required parameter, --name, which takes the name of
the domain to deprecate.
As with register-domain, no output is returned. If you use list-domains to view the registered
domains, however, you will see that the domain no longer appears among them. You can also use --
registration-status DEPRECATED.
See Also
• deprecate-domain in the AWS CLI Command Reference
• describe-domain in the AWS CLI Command Reference
• list-domains in the AWS CLI Command Reference
• register-domain in the AWS CLI Command Reference
110
AWS Command Line Interface User Guide
General troubleshooting tip: ensure you're
running a recent version of the AWS CLI
How you update your version of the AWS CLI depends on how you originally installed it. For example,
if you installed the AWS CLI using pip, then run pip install --upgrade as described on Upgrading to the
latest version of the AWS CLI (p. 9).
If you used one of the bundled installers, then you should remove the existing installation and then
download and install the latest version of the bundled installer for your operating system.
You can send the output to a text file to capture it for later review or to send it to AWS support when
asked for it.
Here's an example of a command run with and without the --debug option:
When you include the --debug option, details include (among other things):
111
AWS Command Line Interface User Guide
General troubleshooting tip: use the --debug option
112
AWS Command Line Interface User Guide
General troubleshooting tip: use the --debug option
113
AWS Command Line Interface User Guide
General troubleshooting tip: use the --debug option
content-type:application/x-www-form-urlencoded; charset=utf-8
host:iam.amazonaws.com
x-amz-date:20190812T193618Z
content-type;host;x-amz-date
5f776d91EXAMPLE9b8cb5eb5d6d4a787a33ae41c8cd6eEXAMPLEca69080e1e1f
2019-08-12 12:36:18,344 - MainThread - botocore.auth - DEBUG - StringToSign:
AWS4-HMAC-SHA256
20190812T193618Z
20190812/us-east-1/iam/aws4_request
ab7e367eEXAMPLE2769f178ea509978cf8bfa054874b3EXAMPLE8d043fab6cc9
2019-08-12 12:36:18,344 - MainThread - botocore.auth - DEBUG - Signature:
d85a0EXAMPLEb40164f2f539cdc76d4f294fe822EXAMPLE18ad1ddf58a1a3ce7
2019-08-12 12:36:18,344 - MainThread - botocore.endpoint - DEBUG - Sending http request:
<AWSPreparedRequest stream_output=False, method=POST, url=https://iam.amazonaws.com/,
headers={'Content-Type': b'application/x-www-form-urlencoded; charset=utf-8',
'User-Agent': b'aws-cli/1.16.215 Python/3.7.3 Linux/4.14.133-113.105.amzn2.x86_64
botocore/1.12.205', 'X-Amz-Date': b'20190812T193618Z', 'Authorization': b'AWS4-HMAC-
SHA256 Credential=AKIA01234567890EXAMPLE-east-1/iam/aws4_request, SignedHeaders=content-
type;host;x-amz-date, Signature=d85a07692aceb401EXAMPLEa1b18ad1ddf58a1a3ce7EXAMPLE',
'Content-Length': '36'}>
2019-08-12 12:36:18,344 - MainThread - urllib3.util.retry - DEBUG - Converted retries
value: False -> Retry(total=False, connect=None, read=None, redirect=0, status=None)
2019-08-12 12:36:18,344 - MainThread - urllib3.connectionpool - DEBUG - Starting new HTTPS
connection (1): iam.amazonaws.com:443
2019-08-12 12:36:18,664 - MainThread - urllib3.connectionpool - DEBUG - https://
iam.amazonaws.com:443 "POST / HTTP/1.1" 200 570
2019-08-12 12:36:18,664 - MainThread - botocore.parsers - DEBUG - Response headers: {'x-
amzn-RequestId': '74c11606-bd38-11e9-9c82-559da0adb349', 'Content-Type': 'text/xml',
'Content-Length': '570', 'Date': 'Mon, 12 Aug 2019 19:36:18 GMT'}
2019-08-12 12:36:18,664 - MainThread - botocore.parsers - DEBUG - Response body:
b'<ListGroupsResponse xmlns="https://iam.amazonaws.com/doc/2010-05-08/">\n
<ListGroupsResult>\n <IsTruncated>false</IsTruncated>\n <Groups>\n
<member>\n <Path>/</Path>\n <GroupName>MyTestGroup</GroupName>
\n <Arn>arn:aws:iam::123456789012:group/MyTestGroup</Arn>\n
<GroupId>AGPA1234567890EXAMPLE</GroupId>\n <CreateDate>2019-08-12T19:34:04Z</
CreateDate>\n </member>\n </Groups>\n </ListGroupsResult>\n <ResponseMetadata>\n
<RequestId>74c11606-bd38-11e9-9c82-559da0adb349</RequestId>\n </ResponseMetadata>\n</
ListGroupsResponse>\n'
2019-08-12 12:36:18,665 - MainThread - botocore.hooks - DEBUG - Event needs-
retry.iam.ListGroups: calling handler <botocore.retryhandler.RetryHandler object at
0x7fdf16e9a780>
2019-08-12 12:36:18,665 - MainThread - botocore.retryhandler - DEBUG - No retry needed.
2019-08-12 12:36:18,665 - MainThread - botocore.hooks - DEBUG - Event after-
call.iam.ListGroups: calling handler <function json_decode_policies at 0x7fdf189b1d90>
{
"Groups": [
{
114
AWS Command Line Interface User Guide
I get the error "command not found" when I run aws
"Path": "/",
"GroupName": "MyTestGroup",
"GroupId": "AGPA123456789012EXAMPLE",
"Arn": "arn:aws:iam::123456789012:group/MyTestGroup",
"CreateDate": "2019-08-12T19:34:04Z"
}
]
}
If you use pip to install the AWS Command Line Interface (AWS CLI), you might need to add the folder
that contains the aws program to your operating system's PATH environment variable, or change its
mode to make it executable.
You might need to add the aws executable to your operating system's PATH environment variable.
Follow the steps in the appropriate procedure:
• Windows – Add the AWS CLI Executable to Your Command Line Path (p. 14)
• macOS – Add the AWS CLI Executable to Your macOS Command Line Path (p. 17)
• Linux – Add the AWS CLI Executable to Your Command Line Path (p. 10)
To add run permission for your user, run the following command, substituting ~/.local/bin/aws with
the path on your computer:
$ chmod +x ~/.local/bin/aws
115
AWS Command Line Interface User Guide
I get an "invalid credentials" error
Most commands call a single action with a name that matches the command name; however, custom
commands like aws s3 sync call multiple APIs. You can see which APIs a command calls by using the
--debug option.
If you are sure that the user or role has the proper permissions assigned by policy, then ensure that your
CLI command is using the credentials you expect. See the next section about credentials (p. 116) to
verify that the credentials the CLI is using are the ones you expect.
For information about assigning permissions to IAM users and roles, see Overview of Access
Management: Permissions and Policies in the IAM User Guide.
The following example shows how to check the credentials used for the default profile.
The following example shows how to check the credentials of a named profile.
$ date
If your system clock is not correct within a few minutes, use ntpd to sync it.
116
AWS Command Line Interface User Guide
I get a "signature does not match" error
On Windows, use the date and time options in the Control Panel to configure your system clock.
$ date
If your system clock is not correct within a few minutes, use ntpd to sync it.
On Windows, use the date and time options in the Control Panel to configure your system clock.
If you process your access keys and secret keys using other tools or scripts, such as tools that build the
credentials file on a new instance as part of its creation, those tools and scripts might have their own
handling of special characters that causes them to be transformed into something that AWS no longer
recognizes.
The easy solution is to regenerate the secret key to get one that does not include the special character.
117
AWS Command Line Interface User Guide
118