Aws Cli PDF
Aws Cli PDF
User Guide
AWS Command Line Interface User Guide
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.
AWS Command Line Interface User Guide
Table of Contents
What Is the AWS CLI? .................................................................................................................... 1
How to Use This Guide ........................................................................................................... 1
Supported Services ............................................................................................................... 1
AWS Command Line Interface on GitHub .................................................................................. 1
About Amazon Web Services .................................................................................................. 1
Getting Set Up .............................................................................................................................. 3
Sign Up for Amazon Web Services ........................................................................................... 3
Installing the AWS CLI ............................................................................................................ 4
Choose an Installation Method ......................................................................................... 5
Install the AWS CLI Using the MSI Installer (Windows) ......................................................... 5
Install the AWS CLI Using Pip .......................................................................................... 6
Install the AWS CLI Using the Bundled Installer (Linux, OS X, or Unix) .................................... 8
Test the AWS CLI Installation ......................................................................................... 10
Where to Go from Here ................................................................................................. 10
Uninstalling the AWS CLI .............................................................................................. 10
Configuring the AWS CLI ...................................................................................................... 11
Quick Configuration ...................................................................................................... 11
Configuration Settings and Precedence ........................................................................... 12
Configuration and Credential Files .................................................................................. 12
Named Profiles ........................................................................................................... 13
Environment Variables .................................................................................................. 14
Command Line Options ................................................................................................ 15
Instance Metadata ....................................................................................................... 16
Using an HTTP Proxy ................................................................................................... 16
Assuming a Role ......................................................................................................... 17
Command Completion .................................................................................................. 20
Where to Go from Here ......................................................................................................... 22
Tutorial: Using Amazon EC2 .......................................................................................................... 23
Install the AWS CLI .............................................................................................................. 23
Windows .................................................................................................................... 23
Linux, OS X, or Unix ..................................................................................................... 24
Configure the CLI and Launch an EC2 Instance ........................................................................ 24
Step 1: Configure the AWS CLI ...................................................................................... 24
Step 2: Create a Security Group, Key Pair, and Role for the EC2 Instance ............................. 24
Step 3: Launch and Connect to the Instance ..................................................................... 25
Using the AWS CLI ...................................................................................................................... 27
Getting Help ....................................................................................................................... 27
AWS CLI Documentation .............................................................................................. 28
API Documentation ...................................................................................................... 28
Command Structure ............................................................................................................. 28
Specifying Parameter Values ................................................................................................. 29
Common Parameter Types ............................................................................................ 29
Using JSON for Parameters ........................................................................................... 31
Loading Parameters from a File ...................................................................................... 33
Generate CLI Skeleton ......................................................................................................... 34
Controlling Command Output ................................................................................................. 37
How to Select the Output Format .................................................................................... 37
How to Filter the Output with the --query Option ............................................................. 38
JSON Output Format .................................................................................................... 40
Text Output Format ...................................................................................................... 41
Table Output Format ..................................................................................................... 42
Shorthand Syntax ................................................................................................................ 44
Structure Parameters ................................................................................................... 44
List Parameters ........................................................................................................... 44
Working with Services .................................................................................................................. 46
iii
AWS Command Line Interface User Guide
DynamoDB ......................................................................................................................... 46
Amazon EC2 ...................................................................................................................... 48
Using Key Pairs ........................................................................................................... 48
Using Security Groups .................................................................................................. 50
Using Instances ........................................................................................................... 55
Amazon Glacier ................................................................................................................... 61
Create an Amazon Glacier Vault ..................................................................................... 61
Prepare a File for Uploading .......................................................................................... 63
Initiate a Multipart Upload and Upload Files ...................................................................... 62
Complete the Upload .................................................................................................... 63
AWS Identity and Access Management ................................................................................... 65
Create New IAM Users and Groups ................................................................................ 65
Set an IAM Policy for an IAM User .................................................................................. 67
Set an Initial Password for an IAM User ........................................................................... 67
Create Security Credentials for an IAM User ..................................................................... 68
Amazon S3 ......................................................................................................................... 68
Using High-Level s3 Commands ..................................................................................... 69
Using API Level (s3api) Commands ................................................................................ 74
Amazon SNS ...................................................................................................................... 75
Create a Topic ............................................................................................................. 75
Subscribe to a Topic ..................................................................................................... 75
Publish to a Topic ......................................................................................................... 76
Unsubscribe from a Topic .............................................................................................. 76
Delete a Topic ............................................................................................................. 77
Amazon SWF ...................................................................................................................... 77
List of Amazon SWF Commands .................................................................................... 77
Working with Amazon SWF Domains .............................................................................. 80
Document History ........................................................................................................................ 84
iv
AWS Command Line Interface User Guide
How to Use This Guide
The AWS Command Line Interface is a unified tool to manage your AWS services. With just one tool to
download and configure, you can control multiple AWS services from the command line and automate
them through scripts.
Supported Services
For a list of the available services you can use with AWS Command Line Interface, see Supported
Services.
1
AWS Command Line Interface User Guide
About Amazon Web Services
synchronization (messaging and queuing). AWS uses a pay-as-you-go service model. You are charged
only for the services that you—or your applications—use. Also, to make AWS more approachable as a
platform for prototyping and experimentation, AWS offers a free usage tier. On this tier, services are free
below a certain level of usage. For more information about AWS costs and the Free Tier, see Test-Driving
AWS in the Free Usage Tier. To obtain an AWS account, open the AWS home page and then click Sign
Up.
2
AWS Command Line Interface User Guide
Sign Up for Amazon Web Services
Before you can start using the AWS Command Line Interface, you must sign up for an AWS account (if
you don't already have one) and set up your CLI environment. Depending on your operating system and
environment, there are different ways to install the AWS CLI: an MSI installer, a bundled installer, or pip.
The following sections will help you decide which option to use.
Note
The AWS CLI makes API calls to services over HTTPS. Outbound connections on TCP port 443
must be enabled in order to perform calls.
Topics
• Sign Up for Amazon Web Services (p. 3)
• Installing the AWS Command Line Interface (p. 4)
• Configuring the AWS Command Line Interface (p. 11)
• Where to Go from Here (p. 22)
Part of the sign-up procedure involves receiving a phone call and entering a PIN using the phone
keypad.
AWS sends you a confirmation email after the sign-up process is complete. At any time, you can view
your current account activity and manage your account by going to http://aws.amazon.com and clicking
My Account/Console.
3
AWS Command Line Interface User Guide
Installing the AWS CLI
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 by using the AWS
Management Console. We recommend that you use IAM access keys instead of AWS root account
access keys. IAM lets you securely control access to AWS services and resources in your AWS account.
Note
To create access keys, you must have permissions to perform the required IAM actions. For
more information, see Granting IAM User Permission to Manage Password Policy and Credentials
in Using IAM.
Your secret key will no longer be available through the AWS Management Console; you will have
the only copy. Keep it confidential in order to protect your account, and never email it. Do not share
it 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.
Related topics
Topics
• Choose an Installation Method (p. 5)
• Install the AWS CLI Using the MSI Installer (Windows) (p. 5)
• Install the AWS CLI Using Pip (p. 6)
• Install the AWS CLI Using the Bundled Installer (Linux, OS X, or Unix) (p. 8)
• Test the AWS CLI Installation (p. 10)
• Where to Go from Here (p. 10)
4
AWS Command Line Interface User Guide
Choose an Installation Method
Note
The awscli package may be available in repositories for other package managers such as APT,
yum and Homebrew, but it is not guaranteed to be the latest version. To make sure you have
the latest version, use one of the installation methods described here.
Note
The MSI installer for the AWS CLI does not currently work with Windows Server 2008
(version 6.0.6002). Please use pip (p. 6) to install with this version of Windows.
2. Run the downloaded MSI installer.
3. Follow the instructions that appear.
5
AWS Command Line Interface User Guide
Install the AWS CLI Using Pip
Don't include the prompt symbol ('>' 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.
Prerequisites
• Windows, Linux, OS X, or Unix
• Python 2 version 2.6.5+ or Python 3 version 3.3+
• Pip
$ python --version
If you don't have Python installed, follow the procedure at Install Python (p. 6) to set it up.
$ pip --help
If you don't have pip installed. follow the procedure at Install pip (p. 7).
Install Python
If you don't have Python installed, install version 2.7 or 3.4 using one of the following methods:
On Windows or OS X, download the Python package for your operating system from python.org and run
the installer. These installers include pip.
$ python --version
Note
If your Linux distribution came with Python, you may need to install the Python developer
package in order to get the headers and libraries required to compile extensions and install
the AWS CLI. Install the developer package (typically named python-dev or python-devel)
using your package manager.
6
AWS Command Line Interface User Guide
Install the AWS CLI Using Pip
2. If Python 2.7 or later is not installed, install it with your distribution's package manager. The command
and package name varies:
3. Open a command prompt or shell and run the following command to verify that Python installed
correctly:
$ python --version
Python 2.7.9
Install pip
Install pip by using the script provided by the Python Packaging Authority.
$ curl -O https://bootstrap.pypa.io/get-pip.py
The script downloads and installs the latest version of pip and another required package named
setuptools.
2. Run the script with Python:
Invoking version 2.7 of Python directly by using the python27 command instead of python ensures
that pip is installed in the proper location, even if an older system version of Python is present on
your system.
7
AWS Command Line Interface User Guide
Install the AWS CLI Using the Bundled Installer (Linux,
OS X, or Unix)
Windows
Linux, OS X, or Unix
Note
If you installed a new version of Python alongside an older version that came with your distribution,
you may get an error like the following when trying to invoke pip with sudo:
To work around this issue, use which pip to locate the executable, and then invoke it directly
by using an absolute path when installing the AWS CLI:
$ which pip
/usr/local/bin/pip
$ sudo /usr/local/bin/pip install awscli
Pip installs the aws executable to /usr/bin/aws. The awscli library (which does the actual work) is
installed to the 'site-packages' folder in Python's installation directory.
Prerequisites
• Linux, OS X, or Unix
• Python 2 version 2.6.5+ or Python 3 version 3.3+
8
AWS Command Line Interface User Guide
Install the AWS CLI Using the Bundled Installer (Linux,
OS X, or Unix)
$ python --version
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 Python (p. 6).
On Linux and OS X, here are the three commands that correspond to each step:
Tip
If you don't have unzip, use your Linux distribution's built in package manager to install it,
typically with either sudo yum install unzip or sudo apt-get install unzip.
The third command installs the AWS CLI at /usr/local/aws and create 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.
Important
The bundled installer does not support installing to paths that contain spaces.
$ ./awscli-bundle/install -h
This will install the AWS CLI to the default location (~/.local/lib/aws) and create a symbolic link
(symlink) at ~/bin/aws. Make sure that ~/bin is in your PATH environment variable for the symlink to
work:
9
AWS Command Line Interface User Guide
Test the AWS CLI Installation
$ 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, etc).
$ aws help
Pip
Run the following command to uninstall the AWS CLI using pip.
Bundled Installer
The bundled installer does not put anything outside of the installation directory except the optional symlink,
so uninstalling is as simple as deleting those two items.
Windows
To uninstall the AWS CLI in Windows, open the Control Panel and select Programs and Features. Select
the entry named AWS Command Line Interface and click Uninstall to launch the uninstaller. Confirm that
you wish to uninstall the AWS CLI when prompted.
You can also launch the Programs and Features menu from the command line with the following command:
> appwiz.cpl
10
AWS Command Line Interface User Guide
Configuring the AWS CLI
Topics
• Quick Configuration (p. 11)
• Configuration Settings and Precedence (p. 12)
• Configuration and Credential Files (p. 12)
• Named Profiles (p. 13)
• Environment Variables (p. 14)
• Command Line Options (p. 15)
• Instance Metadata (p. 16)
• Using an HTTP Proxy (p. 16)
• Assuming a Role (p. 17)
• Command Completion (p. 20)
Quick Configuration
For general use, the aws configure command is the fastest way to setup your AWS CLI installation.
$ 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
The AWS CLI will prompt you for four pieces of information. AWS Access Key ID and AWS Secret Access
Key are your account credentials. If you don't have keys, see the Getting Set Up (p. 3) section earlier
in this guide.
Default region is the name of the region you want to make calls against by default. This is usually the
region closest to you, but it can be any region.
Note
You must specify an AWS region when using the AWS CLI. For a list of services and available
regions, see Regions and Endpoints.
Default output format can be either json, text, or table. If you don't specify an output format, json will be
used.
If you have multiple profiles, you can configure additional, named profiles by using the --profile option.
11
AWS Command Line Interface User Guide
Configuration Settings and Precedence
To update any of your settings, simply run aws configure again and enter new values as appropriate.
The next sections contains more information on the files that aws configure creates, additional settings,
and named profiles.
The AWS CLI looks for credentials and configuration settings in the following order:
1. Command Line Options – region, output format and profile can be specified as command options to
override default settings.
2. Environment Variables – AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, etc.
3. The AWS credentials file – located at ~/.aws/credentials on Linux, OS X, or Unix, or at
C:\Users\USERNAME\.aws\credentials on Windows.This file can contain multiple named profiles
in addition to a default profile.
4. The CLI configuration file – typically located at ~/.aws/config on Linux, OS X, or Unix, or at
C:\Users\USERNAME\.aws\config on Windows. This file can contain a default profile, named
profiles, and CLI specific configuration parameters for each.
5. Instance profile credentials – these credentials can be used on EC2 instances with an assigned
instance role, and are delivered through the Amazon EC2 metadata service.
For example, the following commands list the contents of the .aws folder:
Linux, OS X, or Unix
$ ls ~/.aws
Windows
In order to separate credentials from less sensitive options, region and output format are stored in a
separate file named config in the same folder.
The default file location for the config file can be overridden by setting the AWS_CONFIG_FILE environment
variable to another local path. See Environment Variables (p. 14) for details.
Storing Credentials in Config
The AWS CLI will also read credentials from the config file. If you want to keep all of your profile
settings in a single file, you can. If there are ever credentials in both locations for a profile (say
you used aws configure to update the profile's keys), the keys in the credentials file will take
precendence.
If you use one of the SDKs in addition to the AWS CLI, you may notice additional warnings if
credentials are not stored in their own file.
The files generated by the CLI for the profile configured in the previous section look like this:
12
AWS Command Line Interface User Guide
Named Profiles
~/.aws/credentials
[default]
aws_access_key_id=AKIAIOSFODNN7EXAMPLE
aws_secret_access_key=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
~/.aws/config
[default]
region=us-west-2
output=json
aws_session_token – AWS session token. A session token is only required if you are using temporary
security credentials.
Named Profiles
The AWS CLI supports named profiles 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.
~/.aws/credentials
[default]
aws_access_key_id=AKIAIOSFODNN7EXAMPLE
aws_secret_access_key=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
[user2]
aws_access_key_id=AKIAI44QH8DHBEXAMPLE
aws_secret_access_key=je7MtGbClwBF/2Zp9Utk/h3yCo8nvbEXAMPLEKEY
Each profile uses different credentials—perhaps from two different IAM users—and can also use different
regions and output formats.
~/.aws/config
[default]
region=us-west-2
output=json
13
AWS Command Line Interface User Guide
Environment Variables
[profile user2]
region=us-east-1
output=text
Important
The AWS credentials file uses a different naming format than the CLI config file for named
profiles. Do not include the 'profile ' prefix when configuring a named profile in the AWS credentials
file.
If you are going to use a different profile for multiple commands, you can avoid specifying the profile in
every command by setting the AWS_DEFAULT_PROFILE environment variable at the command line
Linux, OS X, or Unix
$ export AWS_DEFAULT_PROFILE=user2
Windows
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. More on variables in the next section.
Environment Variables
Environment variables override configuration and credential files and can be useful for scripting or
temporarily setting a named profile as the default.
AWS_SECRET_ACCESS_KEY – AWS secret key. Access and secret key variables override credentials
stored in credential and config files.
AWS_SESSION_TOKEN – session token. A session token is only required if you are using temporary
security credentials.
AWS_DEFAULT_REGION – AWS region. This variable overrides the default region of the in-use profile,
if set.
AWS_DEFAULT_PROFILE – name of the CLI profile to use. This can be the name of a profile stored in
a credential or config file, or default to use the default profile.
14
AWS Command Line Interface User Guide
Command Line Options
If the config file variable is set, aws configure will write region and output settings to the specified file,
and the CLI will attempt to read profiles' settings from there instead of the default file (~/.aws/config).
Credentials will still be read from and written to the default credentials file (~/.aws/credentials).
The following example shows how you would configure environment variables for the default user from
earlier in this guide.
Linux, OS X, or Unix
$ export AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
$ export AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
$ export AWS_DEFAULT_REGION=us-west-2
Windows
--endpoint-url – The endpoint to make the call against. The endpoint can be the address of a proxy or
an endpoint URL for the in-use AWS region. Specifying an endpoint is not required for normal use as the
AWS CLI determines which endpoint to call based on the in-use region.
The above options override the corresponding profile settings for a single operation. Each takes a string
argument with a space or equals sign ("=") separating the argument from the option name. Quotes around
the argument are not required unless the argument string contains a space.
Tip
You can use the --profile option with aws configure to setup additional profiles
Common uses for command line options include checking your resources in multiple regions and changing
output format for legibility or ease of use when scripting. For example, if you are not sure which region
your instance is running in you could run the describe-instances command against each region until you
find it:
15
AWS Command Line Interface User Guide
Instance Metadata
|DescribeInstances|
+-----------------+
$ aws ec2 describe-instances --output table --region us-west-1
-------------------
|DescribeInstances|
+-----------------+
$ aws ec2 describe-instances --output table --region us-west-2
------------------------------------------------------------------------------
| DescribeInstances |
+----------------------------------------------------------------------------+
|| Reservations ||
|+-------------------------------------+------------------------------------+|
|| OwnerId | 012345678901 ||
|| ReservationId | r-abcdefgh ||
|+-------------------------------------+------------------------------------+|
||| Instances |||
||+------------------------+-----------------------------------------------+||
||| AmiLaunchIndex | 0 |||
||| Architecture | x86_64 |||
...
Command line option parameter types (string, boolean, etc.) are discussed in detail in the Specifying
Parameter Values for the AWS Command Line Interface (p. 29) section later in this guide.
Instance Metadata
To use the CLI from an EC2 instance, create a role that has access to the resources needed and assign
that role to the instance when it is launched. Launch the instance and check to see if the AWS CLI is
already installed (it comes pre-installed on Amazon Linux).
Install the AWS CLI if necessary and configure a default region to avoid having to specify it in every
command. You can set the region using aws configure without entering 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
Default region name [None]: us-west-2
Default output format [None]: json
The AWS CLI will read credentials from the instance metadata. For more information, see Granting
Applications that Run on Amazon EC2 Instances Access to AWS Resources in Using IAM.
Linux, OS X, or Unix
$ export HTTP_PROXY=http://a.b.c.d:n
$ export HTTPS_PROXY=http://w.x.y.z:m
Windows
16
AWS Command Line Interface User Guide
Assuming a Role
In these examples, http://a.b.c.d:n and http://w.x.y.z:m are the IP addresses and ports for
the HTTP and HTTPS proxies.
Authenticating to a Proxy
The AWS CLI supports HTTP Basic authentication. Specify a username and password in the proxy URL
like this:
Linux, OS X, or Unix
$ export HTTP_PROXY=http://username:password@a.b.c.d:n
$ export HTTPS_PROXY=http://username:password@w.x.y.z:m
Windows
Note
The AWS CLI does not support NTLM proxies.
Linux, OS X, or Unix
$ export NO_PROXY=169.254.169.254
Windows
Assuming a Role
You can configure the AWS Command Line Interface to use a role by creating a profile for the role in the
~/.aws/config file. The following example shows a role profile named marketingadmin that is
assumed by the default profile.
[profile marketingadmin]
role_arn = arn:aws:iam::123456789012:role/marketingadmin
source_profile = default
In this case, the default profile is an IAM user with credentials and permission to assume a role named
marketingadmin. To access the role, you create a named profile. Instead of configuring this profile with
credentials, you specify the ARN of the role and the name of the profile that has access to it.
17
AWS Command Line Interface User Guide
Assuming a Role
Topics
• Configuring and Using a Role (p. 18)
• Using Multifactor Authentication (p. 19)
• Cross Account Roles (p. 20)
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 target IAM user or group 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 group to assume it. The
following example shows a trust relationship that allows a role to be assumed by an IAM user named
jonsmith:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::123456789012:user/jonsmith"
},
"Action": "sts:AssumeRole"
}
]
}
You can also grant assume role permission to an IAM group, and create the trust relationship between
the role and the group. That way, any IAM users you add to the group can assume the role. All the user
needs to do is run aws configure, enter their access keys, and configure the role profile in
~/.aws/config as shown above.
Next, modify your IAM user or group's policy The following example shows an AWS Identity and Access
Management policy that allows an IAM user to assume the marketingadmin role:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "sts:AssumeRole",
"Resource": "arn:aws:iam::123456789012:role/marketingadmin"
}
]
}
18
AWS Command Line Interface User Guide
Assuming a Role
The user doesn't need to have any additional permissions to run commands using the role profile. If you
want your users to be able to access AWS resources without using the role, apply additional inline or
managed policies for those resources.
With the role profile, role permissions, trust relationship and user permissions applied, you can assume
the role at the command line by using the profile option, for example:
To use the role for multiple calls, you can set the AWS_DEFAULT_PROFILE environment variable for
the current session from the command line:
Linux, OS X, or Unix
$ export AWS_DEFAULT_PROFILE=marketingadmin
Windows
For more information on configuring IAM users, groups and roles, see Users and Groups and Roles in
the AWS Identity and Access Management User Guide.
First, modify the trust relationship on the role to require multifactor authentication:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": { "AWS": "arn:aws:iam::123456789012:user/jonsmith" },
"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:
[profile marketingadmin]
role_arn = arn:aws:iam::123456789012:role/marketingadmin
source_profile = default
mfa_serial = arn:aws:iam::123456789012:mfa/jonsmith
The role requires MFA in order to be assumed by any user, but the actual MFA device ARN is specified
in the role profile's configuration on the user's machine and varies between users. This allows many users
to assume the same role using their individual MFA devices.
19
AWS Command Line Interface User Guide
Command Completion
If you use an external ID to provide additional control over who can assume a role across accounts, add
an external_id parameter to the role profile:
[profile crossaccountrole]
role_arn = arn:aws:iam::123456789012:role/xaccount
source_profile = default
mfa_serial = arn:aws:iam::123456789012:mfa/jonsmith
external_id = 123456
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. This feature is not automatically installed so you need
to configure it manually.
Configuring command completion requires two pieces of information: the name of the shell you are using
and the location of the aws_completer script.
Completion on Amazon Linux
Command completion is configured by default on instances running Amazon Linux.
echo $SHELL – show the shell's installation directory. This will usually match 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, which will locate the completer for you.
20
AWS Command Line Interface User Guide
Command Completion
$ which aws_completer
/usr/local/bin/aws_completer
Bundled Installer – if you used the bundled installer per the instructions in the previous section, the AWS
completer will be located in the bin subfolder of the installation directory.
$ ls /usr/local/aws/bin
activate
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.
tcsh – complete for tcsh takes a word type and pattern to define the completion behavior.
% source /usr/local/bin/aws_zsh_completer.sh
The AWS CLI uses bash compatibility auto completion (bashcompinit) for zsh support. For further
details, refer to the top of aws_zsh_completer.sh.
Note
If you installed the AWS CLI using the bundled installer, add the install location to your PATH
variable to allow command completion to find it.
$ export PATH=/usr/local/aws/bin:$PATH
21
AWS Command Line Interface User Guide
Where to Go from Here
$ aws sTAB
s3 ses sqs sts swf
s3api sns storagegateway support
Finally, to ensure that completion continues to work after a reboot, add the configuration command that
you used to enable command completion to your shell profile. If you added a directory to your PATH
variable, put the export statement in your profile as well.
The following example appends the profile for a bash user who installed the AWS CLI to /usr/local/aws
using the bundled installer:
22
AWS Command Line Interface User Guide
Install the AWS CLI
Deploying a Development
Environment in Amazon EC2 Using
the AWS Command Line Interface
This tutorial details how to set up a development environment in Amazon EC2 using the AWS CLI. It
includes a short version of the installation and configuration instructions, and it can be run start to finish
on Windows, Linux, OS X, or Unix.
For complete installation and configuration instructions, see the Getting Set Up (p. 3) section of this
guide. More information on the commands used to call Amazon EC2 is available under Working with
Services (p. 46).
Topics
• Install the AWS CLI (p. 23)
• Configure the CLI and Launch an EC2 Instance (p. 24)
Windows
1. Download the appropriate MSI installer.
23
AWS Command Line Interface User Guide
Linux, OS X, or Unix
Linux, OS X, or Unix
These steps require that you have a working installation of Python 2 version 2.6.5+ or Python 3 version
3.3+. If you encounter any issues using the following steps, see the full installation instructions in the
AWS Command Line Interface User Guide.
1. Download and run the installation script from the pip website:
$ 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
The AWS CLI will prompt you for the following information:
• AWS Access Key ID and AWS Secret Access Key – These are your account credentials. If you don't
have keys, see How Do I Get Security Credentials? in the Amazon Web Services General Reference.
• Default region name – This is the name of the region you want to make calls against by default.
Note
Use us-west-2 for this tutorial (the AMI we will use is specific to this region). You can change
the default region later by running aws configure again.
• Default output format – This format can be either json, text, or table. If you don't specify an output
format, json will be used.
24
AWS Command Line Interface User Guide
Step 3: Launch and Connect to the Instance
1. First, create a new security group and add a rule that allows incoming traffic over port 22 for SSH.
2. Replace the CIDR range in the above with the one that you will connect from for more security. You
can use the aws ec2 describe-security-groups command to admire your handiwork.
3. Next, create a key pair, which allows you to connect to the instance.
This command saves the contents of the key to a file called devenv-key.pem.
Windows
In the Windows Command Processor, enclose queries with double quotes instead of single
quotes.
4. On Linux, you will also need to change the file mode so that only you have access to the key file.
2. The instance will take a few moments to launch. Once the instance is up and running, the following
command will retrieve the public IP address that you will use to connect to the instance.
3. To connect to the instance, use the public IP address and private key with your preferred terminal
program. On Linux, OS X, or Unix, you can do this from the command line with the following command:
25
AWS Command Line Interface User Guide
Step 3: Launch and Connect to the Instance
SSH on Windows
On Windows, you can use the PuTTY terminal application available here. Get putty.exe
and puttygen.exe from the downloads page.
Use puttygen.exe to convert your private key to a .ppk file required by PuTTY. Launch
putty.exe, enter the public IP address of the instance in the Host Name field, and set the
connection type to SSH.
In the Category panel, navigate to Connection > SSH > Auth, and click Browse to select
your .ppk file, and then click Open to connect.
4. The terminal will prompt you to accept the server's public key. Type yes and click Enter to complete
the connection.
You've now configured a security group, created a key pair, launched an EC2 instance, and connected
to it without ever leaving the command line.
26
AWS Command Line Interface User Guide
Getting Help
This section introduces the common features and calling patterns used throughout the AWS Command
Line Interface.
Topics
• Getting Help with the AWS Command Line Interface (p. 27)
• Command Structure in the AWS Command Line Interface (p. 28)
• Specifying Parameter Values for the AWS Command Line Interface (p. 29)
• Generate CLI Skeleton and CLI Input JSON Parameters (p. 34)
• Controlling Command Output from the AWS Command Line Interface (p. 37)
• Using Shorthand Syntax with the AWS Command Line Interface (p. 44)
$ aws help
The following command lists the available subcommands for Amazon EC2.
The next example lists the detailed help for the EC2 DescribeInstances operation, including descriptions
of its input parameters, filters, and output. Check the examples section of the help if you are not sure how
to phrase a command.
27
AWS Command Line Interface User Guide
AWS CLI Documentation
Windows Users
Pipe the output of the help command to more to view the help file one page at a time. Press the
space bar or Page Down to view more of the document, and q to quit.
Help files sometimes contain links that cannot be viewed or followed from the command line view; these
are preserved in the online AWS CLI reference.
API Documentation
All subcommands in the AWS CLI correspond to calls made against a service's public API. Each service
with a public API, in turn, has a set of API reference documentation that can be found from the service's
homepage on the AWS Documentation website.
The content of an API reference varies based on how the API is constructed and which protocol is used.
Typically, an API reference will contain detailed information on actions supported by the API, data sent
to and from the service, and possible error conditions.
• Actions – Detailed information on parameters (including constraints on length or content) and errors
specific to an action. Actions correspond to subcommands in the AWS CLI.
• Data Types – May contain additional information about object data returned by a subcommand.
• Common Parameters – Detailed information about parameters that are used by all of a service's
actions.
• Common Errors – Detailed information about errors returned by all of a service's actions.
The name and availability of each section may vary depending on the service.
Service-Specific CLIs
Some services have a separate CLI from before a single AWS CLI was created that works 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.
28
AWS Command Line Interface User Guide
Specifying Parameter Values
Parameters can take various types of input values, such as numbers, strings, lists, maps, and JSON
structures.
First, many parameters are simple string or numeric values, such as the key pair name MyKeyPair in
the following example:
Strings without any space characters may be quoted or unquoted. However, strings that include one or
more space characters must be quoted. Use a single quote (') in Linux, OS X, or Unix and Windows
PowerShell, or use a double quote (") in the Windows command prompt, as shown in the following
examples.
Topics
• Common Parameter Types (p. 29)
• Using JSON for Parameters (p. 31)
• Loading Parameters from a File (p. 33)
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 whitespace from the
ASCII character set. Strings that contain whitespace must be surrounded by quotes. Use of symbols and
whitespace other than the standard space character is not recommended and may cause issues when
using the AWS CLI.
Some string parameters can accept binary data from a file. See Binary Files (p. 33) for an example.
29
AWS Command Line Interface User Guide
Common Parameter Types
Timestamp – Timestamps are formatted per the ISO 8601 standard. These are sometimes referred to
as "DateTime" or "Date" type parameters.
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 command against the service without
actually running a query.
The output indicates whether the command was well formed or not. This command also includes a
no-dry-run version of the parameter that can be used to explicitly indicate that the command should be
run normally, although including it is not necessary as this is the default behavior.
Blob – Binary object. Blob parameters take a path to a local file that contains binary data. The path should
not contain any protocol identifier such as http:// or file://.
Map – A sequence of key value pairs specified in JSON or shorthand syntax (p. 44). The following example
reads an item from a 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.
30
AWS Command Line Interface User Guide
Using JSON for Parameters
}
}
The following example specifies the equivalent list of filters in 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 ("Name" and "Values" are both keys in this instance).
Note that 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, on the other hand, are only required if more than one filter is specified. A single
filter version of the above command, formatted in JSON, looks like this:
Some operations require data to be formatted 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 Elastic Block Store device to be mapped at
/dev/sdb on the launching instance.
{
"DeviceName": "/dev/sdb",
"Ebs": {
"VolumeSize": 20,
"DeleteOnTermination": false,
"VolumeType": "standard"
}
}
31
AWS Command Line Interface User Guide
Using JSON for Parameters
To attach multiple devices, list the objects in an array like 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 either enter the JSON directly on the command line (see Quoting Strings (p. 32)), or save it to
a file that is referenced from the command line (see Loading Parameters from a File (p. 33)).
When passing in large blocks of data, you might find it easier to save the JSON to a file and 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 the next section.
For more information about JSON, see Wikipedia - JSON and RFC4627 - The application/json Media
Type for JSON.
Quoting Strings
The way you enter JSON-formatted parameters on the command line differs depending upon your
operating system. Linux, OS X, or Unix and Windows PowerShell use the single quote (') to enclose the
JSON data structure, as in the following example:
The Windows command prompt, on the other hand, uses the double quote (") to enclose the JSON data
structure. In addition, a backslash (\) escape character is required for each double quote (") within the
JSON data structure itself, as in the following example:
Lastly, Windows PowerShell requires a single quote (') to enclose the JSON data structure, as well as a
backslash (\) to escape each double quote (") within the JSON structure, as in the following example:
32
AWS Command Line Interface User Guide
Loading Parameters from a File
Linux, OS X, or Unix
Windows
The file:// prefix option supports Unix-style expansions including '~/', './', and '../'. On Windows, the
'~/' expression expands to C:\Users\User Name\.
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 in an Amazon S3 bucket. This allows you to
access parameter files from any computer, but requires the file to be stored in a publically accessible
location.
33
AWS Command Line Interface User Guide
Generate CLI Skeleton
In the preceding examples, the filename.json file 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 Set
an IAM Policy for an IAM User (p. 67).
Generate CLI Skeleton outputs JSON that outlines all of the parameters that can be specified for the
operation.
1. Execute the run-instances command with the --generate-cli-skeleton option to view the
JSON skeleton.
34
AWS Command Line Interface User Guide
Generate CLI Skeleton
"Tenancy": ""
},
"KernelId": "",
"RamdiskId": "",
"BlockDeviceMappings": [
{
"VirtualName": "",
"DeviceName": "",
"Ebs": {
"SnapshotId": "",
"VolumeSize": 0,
"DeleteOnTermination": true,
"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
}
35
AWS Command Line Interface User Guide
Generate CLI Skeleton
3. Open the skeleton in a text editor and remove any parameters that you will not use:
{
"DryRun": true,
"ImageId": "",
"KeyName": "",
"SecurityGroups": [
""
],
"InstanceType": "",
"Monitoring": {
"Enabled": true
}
}
Leave the DryRun parameter set to true to use EC2's dry run feature, which lets you test your
configuration without creating resources.
4. Fill in the values for the instance type, key name, security group and AMI in your default region. In
this example, ami-dfc39aef is a 64-bit Amazon Linux image in the us-west-2 region.
{
"DryRun": true,
"ImageId": "ami-dfc39aef",
"KeyName": "mykey",
"SecurityGroups": [
"my-sg"
],
"InstanceType": "t2.micro",
"Monitoring": {
"Enabled": true
}
}
5. Pass the JSON configuration to the --cli-input-json parameter using the file:// prefix:
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 dry run error
is shown.
6. Set the DryRun parameter to false to disable the dry run feature.
{
"DryRun": false,
"ImageId": "ami-dfc39aef",
"KeyName": "mykey",
"SecurityGroups": [
"my-sg"
],
36
AWS Command Line Interface User Guide
Controlling Command Output
"InstanceType": "t2.micro",
"Monitoring": {
"Enabled": true
}
}
Topics
• How to Select the Output Format (p. 37)
• How to Filter the Output with the --query Option (p. 38)
• JSON Output Format (p. 40)
• Text Output Format (p. 41)
• Table Output Format (p. 42)
• JSON (json)
• Tab-delimited text (text)
• ASCII-formatted table (table)
As explained in the configuration (p. 11) topic, the output format can be specified in three different ways:
• Using the output option in the configuration file. The following example sets the output to text:
[default]
output=text
$ export AWS_DEFAULT_OUTPUT="table"
37
AWS Command Line Interface User Guide
How to Filter the Output with the --query Option
Note
If the output format is specified in multiple ways, the usual AWS CLI precedence rules (p. 12)
apply. For example, using the AWS_DEFAULT_OUTPUT environment variable overrides any value
set in the config file with output, and a value passed to an AWS CLI command with --output
overrides any value set in the environment or in the config file.
JSON is best for handling the output programmatically via various languages or jq (a command-line
JSON processor). The table format is easy for humans to read, and text format works well with traditional
Unix text processing tools, such as sed, grep, and awk, as well as Windows PowerShell scripts.
38
AWS Command Line Interface User Guide
How to Filter the Output with the --query Option
"VolumeType": "standard",
"VolumeId": "vol-2e410a47",
"State": "in-use",
"SnapshotId": "snap-708e8348",
"CreateTime": "2013-09-18T20:26:15.000Z",
"Size": 8
}
]
}
First, we can display only the first volume from the Volumes list with the following command.
Now, we use the wildcard notation [*] to iterate over the entire list and also filter out three elements:
VolumeId, AvailabilityZone, and Size. Note that the dictionary notation requires that you provide
an alias for each key, like this: {Alias1:Key1,Alias2:Key2}. A dictionary is inherently unordered, so the
ordering of the key-aliases within a structure may not be consistent in some cases.
In the dictionary notation, you can also use chained keys such as key1.key2[0].key3 to filter elements
deeply nested within the structure. The example below demonstrates this with the
Attachments[0].InstanceId key, aliased to simply InstanceId.
39
AWS Command Line Interface User Guide
JSON Output Format
You can also filter multiple elements with the list notation: [key1, key2]. This will format all filtered
attributes into a single ordered list per object, regardless of type.
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 (`) in order for it to be read properly.
Combined with the three output formats that will be 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, visit http://jmespath.org/
specification.html.
40
AWS Command Line Interface User Guide
Text Output Format
examples, the --query option provides powerful ways to filter and format the AWS CLI's JSON formatted
output. If you need more advanced features that may 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.
We strongly recommend that the text output be used along with the --query option to ensure consistent
behavior. This is because the text format alphabetically orders output columns, and similar resources
may not always have the same collection of keys. For example, a JSON representation of a Linux EC2
instance may have elements that are not present in the JSON representation of a Windows instance, or
vice versa. Also, resources may 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 enable
complete control over the output format. In the example below, the command pre-selects which elements
to display and defines the ordering of the columns with the list notation [key1, key2, ...]. This gives
users full confidence that the correct key values will always be displayed in the expected column. Finally,
notice how the AWS CLI outputs 'None' as values for keys that don't exist.
Below is an example of how grep and awk can be used along with a text output from aws ec2
describe-instances command. The first command displays the Availability Zone, state, and instance
ID of each instance in text output. The second command outputs only the instance IDs of all running
instances in the us-west-2a Availability Zone.
41
AWS Command Line Interface User Guide
Table Output Format
The next command shows a similar example for all stopped instances and takes it one step further to
automate changing instance types for each stopped instance.
The text output is useful in Windows PowerShell as well. Because AWS CLI's text output is tab-delimited,
it is easily split into an array in PowerShell using the `t delimiter. The following command displays the
value of the third column (InstanceId) if the first column (AvailabilityZone) matches us-west-2a.
42
AWS Command Line Interface User Guide
Table Output Format
The --query option can be used with the table format to display a set of elements pre-selected from the
raw output. Note the output differences in 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.
43
AWS Command Line Interface User Guide
Shorthand Syntax
Structure Parameters
The shorthand syntax in the AWS CLI makes it easier for users to input parameters that are flat (non-nested
structures). The basic format is shown here.
--option name1=value1,name2=value2,name3=value3
Important
There must be no whitespace between each comma-separated name/value pair.
The previous shorthand example is equivalent to the following example formatted in JSON.
--option '{"name1":"value1","name2":"value2","name3":"value3"}'
The shorthand syntax currently does not support nested structures. A nested structure has one or more
structures as a value or values within itself. Nested structures must be specified in JSON.
List Parameters
Input parameters in a list form can be specified in two ways: JSON and shorthand. The AWS CLI's
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.
44
AWS Command Line Interface User Guide
List Parameters
--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 EC2, where
the input parameter (list of strings) for the --instance-ids option is specified in shorthand.
Next is an example of 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 be tagged.
This is equivalent to the following example formatted in JSON. The JSON parameter is written in multiple
lines solely for readability.
45
AWS Command Line Interface User Guide
DynamoDB
This section provides examples of using the AWS Command Line Interface to access AWS services.
These examples are intended to demonstrate how to use the AWS CLI to perform administrative tasks.
For a complete reference to all of the available commands for each service, see the AWS Command Line
Interface Reference or use the built-in command line help. For more information, see Getting Help with
the AWS Command Line Interface (p. 27).
Topics
• Using Amazon DynamoDB with the AWS Command Line Interface (p. 46)
• Using Amazon EC2 through the AWS Command Line Interface (p. 48)
• Using Amazon Glacier with the AWS Command Line Interface (p. 61)
• AWS Identity and Access Management from the AWS Command Line Interface (p. 65)
• Using Amazon S3 with the AWS Command Line Interface (p. 68)
• Using the AWS Command Line Interface with Amazon SNS (p. 75)
• Using Amazon Simple Workflow Service with the AWS Command Line Interface (p. 77)
The command line format consists of an Amazon DynamoDB API name, followed by the parameters for
that API. The AWS CLI supports a shorthand syntax for the parameter values, as well as JSON.
For example, the following command will create a table named MusicCollection.
Note
For easier readability, long commands in this section are broken into separate lines.The backslash
character lets you copy and paste (or type) multiple lines into a Linux terminal. If you are using
46
AWS Command Line Interface User Guide
DynamoDB
a shell that does not use backslash to escape characters, replace the backslash with another
escape character, or remove the backslashes and put the entire command on a single line.
The following commands will add new items to the table. These example use a combination of shorthand
syntax and JSON.
On the command line, it can be difficult to compose valid JSON; however, the AWS CLI can read JSON
files. For example, consider the following JSON snippet, which is stored in a file named
key-conditions.json:
{
"Artist": {
"AttributeValueList": [
{
"S": "No One You Know"
}
],
"ComparisonOperator": "EQ"
},
"SongTitle": {
"AttributeValueList": [
{
"S": "Call Me Today"
}
],
"ComparisonOperator": "EQ"
}
}
You can now issue a Query request using the AWS CLI. In this example, the contents of the
key-conditions.json file are used for the --key-conditions parameter:
47
AWS Command Line Interface User Guide
Amazon EC2
For more documentation on using the AWS CLI with DynamoDB, go to http://docs.aws.amazon.com/cli/
latest/reference/dynamodb/index.html.
Tip
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 DynamoDB. Instead, all of the API actions are rerouted to DynamoDB Local.
When your application creates a table or modifies data, those changes are written 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. 11).
For examples of common tasks for Amazon EC2, see the following topics.
Topics
• Using Key Pairs (p. 48)
• Using Security Groups (p. 50)
• Using Amazon EC2 Instances (p. 55)
Topics
• Creating a Key Pair (p. 49)
• Displaying Your Key Pair (p. 49)
• Deleting Your Key Pair (p. 50)
48
AWS Command Line Interface User Guide
Using Key Pairs
Note that for Windows PowerShell, the > file redirection defaults to UTF-8 encoding, which cannot be
used with some SSH clients. So, you must explicitly specify ASCII encoding in the out-file command.
Your private key is not stored in AWS and can only be retrieved when it is created.
If you're using an SSH client on a Linux computer to connect to your instance, use the following command
to set the permissions of your private key file so that only you can read it.
49
AWS Command Line Interface User Guide
Using Security Groups
the EC2 management console or by calling aws ec2 describe-key-pairs. For example, you can
view the fingerprint for MyKeyPair by using the following command:
{
"KeyPairs": [
{
"KeyName": "MyKeyPair",
"KeyFingerprint":
"1f:51:ae:28:bf:89:e9:d8:1f:25:5d:37:2d:7d:b8:ca:9f:f5:f1:6f"
}
]
}
For more information on keys and fingerprints, see the Amazon EC2 Key Pairs page in the Amazon EC2
User Guide.
{
"return": "true"
}
You can use the AWS CLI to create, add rules to, and delete your security groups.
Note
Before you try the example commands, set your default credentials.
Topics
• Creating a Security Group (p. 50)
• Adding Rules to Your Security Group (p. 52)
• Deleting Your Security Group (p. 54)
50
AWS Command Line Interface User Guide
Using Security Groups
EC2-Classic
The following command creates a security group named MySecurityGroup for EC2-Classic:
{
"return": "true",
"GroupId": "sg-903004f8"
}
To view the initial information for MySecurityGroup, use the describe-security-groups command as
follows:
{
"SecurityGroups": [
{
"IpPermissionsEgress": [],
"Description": "My security group"
"IpPermissions": [],
"GroupName": "MySecurityGroup",
"OwnerId": "123456789012",
"GroupId": "sg-903004f8"
}
]
}
EC2-VPC
The following command creates a security group named MySecurityGroup for the specified VPC:
{
"return": "true",
"GroupId": "sg-903004f8"
}
To view the initial information for MySecurityGroup, use the describe-security-groups command as
follows. Note that you can't reference a security group for EC2-VPC by name.
51
AWS Command Line Interface User Guide
Using Security Groups
{
"SecurityGroups": [
{
"IpPermissionsEgress": [
{
"IpProtocol": "-1",
"IpRanges": [
{
"CidrIp": "0.0.0.0/0"
}
],
"UserIdGroupPairs": []
}
],
"Description": "My security group"
"IpPermissions": [],
"GroupName": "MySecurityGroup",
"VpcId": "vpc-1a2b3c4d",
"OwnerId": "123456789012",
"GroupId": "sg-903004f8"
}
]
}
EC2-Classic
The following command adds a rule for RDP to the security group MySecurityGroup:
The following command adds a rule for SSH to the security group for MySecurityGroup:
52
AWS Command Line Interface User Guide
Using Security Groups
{
"return": "true"
}
{
"SecurityGroups": [
{
"IpPermissionsEgress": [],
"Description": "My security group"
"IpPermissions": [
{
"ToPort": 22,
"IpProtocol": "tcp",
"IpRanges": [
{
"CidrIp": "203.0.113.0/24"
}
]
"UserIdGroupPairs": [],
"FromPort": 22
}
],
"GroupName": "MySecurityGroup",
"OwnerId": "123456789012",
"GroupId": "sg-903004f8"
}
]
}
EC2-VPC
The following command adds a rule for RDP to the security group with the ID sg-903004f8:
The following command adds a rule for SSH to the security group with the ID sg-903004f8:
{
"return": "true"
}
53
AWS Command Line Interface User Guide
Using Security Groups
{
"SecurityGroups": [
{
"IpPermissionsEgress": [
{
"IpProtocol": "-1",
"IpRanges": [
{
"CidrIp": "0.0.0.0/0"
}
],
"UserIdGroupPairs": []
}
],
"Description": "My security group"
"IpPermissions": [
{
"ToPort": 22,
"IpProtocol": "tcp",
"IpRanges": [
{
"CidrIp": "203.0.113.0/24"
}
]
"UserIdGroupPairs": [],
"FromPort": 22
}
],
"GroupName": "MySecurityGroup",
"OwnerId": "123456789012",
"GroupId": "sg-903004f8"
}
]
}
EC2-Classic
The following command deletes the security group named MySecurityGroup:
54
AWS Command Line Interface User Guide
Using Instances
{
"return": "true"
}
EC2-VPC
The following command deletes the security group with the ID sg-903004f8:
{
"return": "true"
}
If you launch an instance that is not within the Free Usage 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
Before you try the example command, set your default credentials.
Topics
• Launching an Instance (p. 55)
• Adding a Block Device Mapping to Your Instance (p. 59)
• Adding a Name Tag to Your Instance (p. 60)
• Connecting to Your Instance (p. 60)
• Listing Your Instances (p. 60)
• Terminating Your Instance (p. 60)
Launching an Instance
To launch a single Amazon EC2 instance using the AMI you selected, use the run-instances command.
Depending on the platforms that your account supports, you can launch the instance into EC2-Classic
or EC2-VPC.
Initially, your instance is in the pending state, but will be in the running state in a few minutes.
EC2-Classic
The following command launches a t1.micro instance in EC2-Classic:
55
AWS Command Line Interface User Guide
Using Instances
{
"OwnerId": "123456789012",
"ReservationId": "r-5875ca20",
"Groups": [
{
"GroupName": "MySecurityGroup",
"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",
"ProductCodes": [],
"InstanceId": "i-5203422c",
"ImageId": "ami-173d747e",
"PrivateDnsName": null,
"KeyName": "MyKeyPair",
"SecurityGroups": [
{
"GroupName": "MySecurityGroup",
"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",
56
AWS Command Line Interface User Guide
Using Instances
"Code": "pending"
},
"RootDeviceName": "/dev/sda1",
"VirtualizationType": "hvm",
"RootDeviceType": "ebs",
"Tags": [
{
"Value": "MyInstance",
"Key": "Name"
}
],
"AmiLaunchIndex": 0
}
]
}
EC2-VPC
The following command launches a t1.micro instance in the specified subnet:
{
"OwnerId": "123456789012",
"ReservationId": "r-5875ca20",
"Groups": [
{
"GroupName": "MySecurityGroup",
"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": [
57
AWS Command Line Interface User Guide
Using Instances
{
"GroupName": "MySecurityGroup",
"GroupId": "sg-903004f8"
}
],
"ClientToken": null,
"SubnetId": "subnet-6e7f829e",
"InstanceType": "t1.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": "MySecurityGroup",
"GroupId": "sg-903004f8"
}
],
"SubnetId": "subnet-6e7f829e",
"OwnerId": "123456789012",
"PrivateIpAddress": "10.0.1.114"
}
],
"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"
}
}
58
AWS Command Line Interface User Guide
Using Instances
],
"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 mapping to your instance, specify the --block-device-mappings option when
you use run-instances.
The following example adds a standard Amazon EBS volume, mapped to /dev/sdf, that's 20 GB in
size.
--block-device-mappings "[{\"DeviceName\":\"/dev/sdf\",\"Ebs\":{\"VolumeS
ize\":20,\"DeleteOnTermination\":false}}]"
The following example adds an Amazon EBS volume, mapped to /dev/sdf, based on a snapshot. When
you specify a snapshot, it isn't necessary to specify a volume size, but if you do, it must be greater than
or equal to the size of the snapshot.
--block-device-mappings "[{\"DeviceName\":\"/dev/sdf\",\"Ebs\":{\"Snapshot
Id\":\"snap-xxxxxxxx\"}}]"
The following example adds two instance store volumes. Note that the number of instance store volumes
available to your instance depends on its instance type.
--block-device-mappings "[{\"DeviceName\":\"/dev/sdf\",\"VirtualName\":\"ephem
eral0\"},{\"DeviceName\":\"/dev/sdg\",\"VirtualName\":\"ephemeral1\"}]"
The following example omits a mapping for a device specified by the AMI used to launch the instance
(/dev/sdj):
--block-device-mappings "[{\"DeviceName\":\"/dev/sdj\",\"NoDevice\":\"\"}]"
For more information, see Block Device Mapping in the Amazon EC2 User Guide for Linux Instances.
59
AWS Command Line Interface User Guide
Using Instances
{
"return": "true"
}
For more information, see Tagging Your Resources in the Amazon EC2 User Guide for Linux Instances.
The following command lists your instances that were launched from the following AMIs: ami-x0123456,
ami-y0123456, and ami-z0123456.
After you've finished with the instance, use the terminate-instances command as follows:
60
AWS Command Line Interface User Guide
Amazon Glacier
{
"TerminatingInstances": [
{
"InstanceId": "i-5203422c",
"CurrentState": {
"Code": 32,
"Name": "shutting-down"
},
"PreviousState": {
"Code": 16,
"Name": "running"
}
}
]
}
For more information, see Terminate Your Instance in the Amazon EC2 User Guide for Linux Instances.
Topics
• Create an Amazon Glacier Vault (p. 61)
• Prepare a File for Uploading (p. 63)
• Initiate a Multipart Upload and Upload Files (p. 62)
• Complete the Upload (p. 63)
61
AWS Command Line Interface User Guide
Prepare a File for Uploading
Note
All glacier commands require an account ID parameter. Use a hyphen to specify the current
account.
Linux, OS X, or Unix
Windows
dd is a utility that copies a number of bytes from an input file to an output file. The above example uses
the device file /dev/urandom as a source of random data. fsutil performsa similar function in Windows.
Note
HJ-Split is a free file splitter for Windows and many other platforms.
Amazon Glacier requires the size of each part in bytes (1 MiB in this example), your vault name and an
account ID in order 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.
Linux, OS X, or Unix
62
AWS Command Line Interface User Guide
Complete the Upload
$ UPLOADID="19gaRezEXAMPLES6Ry5YYdqthHOC_kGRCT03L9yetr220UmPtBYKk-OssZtLqy
Fu7sY1_lR7vgFuJV6NtcV5zpsJ"
Windows
Next, use the aws glacier upload-multipart-part command to upload each part.
Note
The above example uses the dollar sign ("$") to dereference the UPLOADID shell variable. On
the Windows command line, use two percent signs (i.e. %UPLOADID%).
You must specify the byte range of each part when you upload it so it can be reassembled in the proper
order by Amazon Glacier. Each piece is 1048576 bytes, so the first piece occupies bytes 0-1048575, the
second 1048576-2097151, and the third 2097152-3145727.
The key to calculating a tree hash correctly when using command line utilities is to store each hash in
binary format and only convert to hexadecimal 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. Split the original file into 1 MiB parts if you haven't already.
63
AWS Command Line Interface User Guide
Complete the Upload
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 outputing hexadecimal. Store the result in a shell variable.
Finally, complete the upload with the aws glacier 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 aws glacier describe-vault:
64
AWS Command Line Interface User Guide
AWS Identity and Access Management
"VaultName": "myvault"
}
It is now safe to remove the part and hash files you created:
$ rm chunk* hash*
For more information on multipart uploads, see Uploading Large Archives in Parts and Computing
Checksums in the Amazon Glacier Developer Guide.
The commands shown here assume that you have set default credentials and a default region.
Topics
• Create New IAM Users and Groups (p. 65)
• Set an IAM Policy for an IAM User (p. 67)
• Set an Initial Password for an IAM User (p. 67)
• Create Security Credentials for an IAM User (p. 68)
{
"Group": {
"GroupName": "MyIamGroup",
"CreateDate": "2012-12-20T03:03:52.834Z",
"GroupId": "AKIAI44QH8DHBEXAMPLE",
"Arn": "arn:aws:iam::123456789012:group/MyIamGroup",
"Path": "/"
}
}
65
AWS Command Line Interface User Guide
Create New IAM Users and Groups
{
"User": {
"UserName": "MyUser",
"Path": "/",
"CreateDate": "2012-12-20T03:13:02.581Z",
"UserId": "AKIAIOSFODNN7EXAMPLE",
"Arn": "arn:aws:iam::123456789012:user/MyUser"
}
}
3. Finally, use the add-user-to-group command to add the user to the group.
{
"Group": {
"GroupName": "MyIamGroup",
"CreateDate": "2012-12-20T03:03:52Z",
"GroupId": "AKIAI44QH8DHBEXAMPLE",
"Arn": "arn:aws:iam::123456789012:group/MyIamGroup",
"Path": "/"
},
"Users": [
{
"UserName": "MyUser",
"Path": "/",
"CreateDate": "2012-12-20T03:13:02Z",
"UserId": "AKIAIOSFODNN7EXAMPLE",
"Arn": "arn:aws:iam::123456789012:user/MyUser"
}
],
"IsTruncated": "false"
}
You can also view IAM users and groups with the AWS Management Console.
66
AWS Command Line Interface User Guide
Set an IAM Policy for an IAM User
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"NotAction": "iam:*",
"Resource": "*"
}
]
}
Verify the policy has been assigned to the user with the list-user-policies command.
{
"PolicyNames": [
"MyPowerUserRole"
],
"IsTruncated": "false"
}
Additional Resources
For more information, see Resources for Learning About Permissions and Policies. 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.
67
AWS Command Line Interface User Guide
Create Security Credentials for an IAM User
{
"LoginProfile": {
"UserName": "MyUser",
"CreateDate": "2013-01-02T21:10:54.339Z",
"MustChangePassword": "false"
}
}
Use the update-login-profile command to update the password for an IAM user.
{
"AccessKey": {
"SecretAccessKey": "je7MtGbClwBF/2Zp9Utk/h3yCo8nvbEXAMPLEKEY",
"Status": "Active",
"CreateDate": "2013-01-02T22:44:12.897Z",
"UserName": "MyUser",
"AccessKeyId": "AKIAI44QH8DHBEXAMPLE"
}
}
Use the delete-access-key command to delete a set of credentials for an IAM user. Specify which
credentials to delete by using the access key ID.
• The first tier, named s3, consists of high-level commands for frequently used operations, such as
creating, manipulating, and deleting objects and buckets.
• The second tier, named s3api, exposes all Amazon S3 operations, including modifying a bucket access
control list (ACL), using cross-origin resource sharing (CORS), or logging policies. It allows you to carry
out advanced operations that may not be possible with the high-level commands alone.
68
AWS Command Line Interface User Guide
Using High-Level s3 Commands
To get a list of all commands available in each tier, use the help argument with the aws s3 or aws
s3api commands:
$ aws s3 help
or
Note
The AWS CLI supports copying, moving, and syncing from Amazon S3 to Amazon S3. These
operations use the service-side COPY operation provided by Amazon S3: 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 Command Line Interface (p. 69)
• Using API-Level (s3api) Commands with the AWS Command Line Interface (p. 74)
Managing Buckets
High-level aws s3 commands support commonly used bucket operations, such as creating, removing,
and listing buckets.
Creating Buckets
Use the aws s3 mb command to create a new bucket. Bucket names must be unique and should be
DNS compliant. Bucket names can contain lowercase letters, numbers, hyphens and periods. Bucket
names can only start and end with a letter or number, and cannot contain a period next to a hyphen or
another period.
$ aws s3 mb s3://bucket-name
Removing Buckets
To remove a bucket, use the aws 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.
69
AWS Command Line Interface User Guide
Using High-Level s3 Commands
This will first delete all objects and subfolders in the bucket and then remove the bucket.
Note
If you are using a versioned bucket that contains previously deleted—but retained—objects, this
command will not allow you to remove the bucket.
Listing Buckets
To list all buckets or their contents, use the aws s3 ls command. Here are some examples of common
usage.
$ aws s3 ls
CreationTime Bucket
------------ ------
2013-07-11 17:08:50 my-bucket
2013-07-24 14:55:44 my-bucket2
The following command lists all objects and folders (prefixes) in a bucket.
$ aws s3 ls s3://bucket-name
Bucket: my-bucket
Prefix:
The following command lists the objects in bucket-name/MyFolder (in other words, objects in
bucket-name filtered by the prefix MyFolder).
$ aws s3 ls s3://bucket-name/MyFolder
Bucket: my-bucket
Prefix: MyFolder/
Managing Objects
The high-level aws s3 commands make it convenient to manage Amazon S3 objects as well. The object
commands include aws s3 cp, aws s3 ls, aws s3 mv, aws s3 rm, and 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 (aws s3 cp,
aws s3 mv, and aws s3 sync) automatically perform a multipart upload when the object is
large.
70
AWS Command Line Interface User Guide
Using High-Level s3 Commands
Failed uploads cannot be resumed when using these commands. If the multipart upload fails
due to a timeout or is manually cancelled 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 can be used to grant permissions on
the object to specified users or groups.You 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 the grantee is to be identified, 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.
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
user@example.com.
The sync command has the following form. Possible source-target combinations are:
The following example synchronizes the contents of an Amazon S3 folder named MyFolder in my-bucket
with the current working directory. 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/MyFolder/MySubdirectory.
71
AWS Command Line Interface User Guide
Using High-Level s3 Commands
Normally, sync only copies missing or outdated files or objects between the source and target. However,
you may supply the --delete option to remove files or objects from the target not present in the source.
The following example, which extends the previous one, shows how this works.
The --exclude and --include options allow you to specify rules to filter the files or objects to be copied
during the sync operation. By default, all items in a specified directory are included in the sync. Therefore,
--include is only needed when specifying exceptions to the --exclude option (for example, --include
effectively means "don't exclude"). The options apply in the order that is specified, as demonstrated in
the following example.
The --exclude and --include options can also filter files or objects to be deleted during a sync
operation with the --delete option. In this case, the parameter string must specify files to be excluded
from, or included for, deletion in the context of the target directory or bucket. The following shows an
example.
72
AWS Command Line Interface User Guide
Using High-Level s3 Commands
The sync command also accepts an --acl option, by which you may set the access permissions for
files copied to Amazon S3. The option accepts private, public-read, and public-read-write
values.
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/MyFolder/MyFile.txt
$ aws s3 rm s3://my-bucket/MyFolder/MyFile.txt
73
AWS Command Line Interface User Guide
Using API Level (s3api) Commands
When the --recursive option is used on a directory/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.
Custom ACLs
With high-level commands, you can use the --acl option to apply pre-defined access control lists (ACLs)
on Amazon S3 objects, but you cannot set bucket-wide ACLs.You can do this with the API-level command,
put-bucket-acl. The following example grants full control to two AWS users (user1@example.com
and user2@example.com) and read permission to everyone.
For details about custom ACLs, see PUT Bucket acl. The s3api ACL commands, such as
put-bucket-acl, use the same shorthand argument notation.
Logging Policy
The API command put-bucket-logging configures bucket logging policy. The following example sets
the logging policy for MyBucket. The AWS user user@example.com will have full control over the log
files, and all users will have access to them. Note that the put-bucket-acl command is required to
grant Amazon S3's log delivery system the necessary permissions (write and read-acp).
logging.json
{
"LoggingEnabled": {
"TargetBucket": "MyBucket",
"TargetPrefix": "MyBucketLogs/",
"TargetGrants": [
{
"Grantee": {
"Type": "AmazonCustomerByEmail",
"EmailAddress": "user@example.com"
},
"Permission": "FULL_CONTROL"
},
74
AWS Command Line Interface User Guide
Amazon SNS
{
"Grantee": {
"Type": "Group",
"URI": "http://acs.amazonaws.com/groups/global/AllUsers"
},
"Permission": "READ"
}
]
}
}
Topics
• Create a Topic (p. 75)
• Subscribe to a Topic (p. 75)
• Publish to a Topic (p. 76)
• Unsubscribe from a Topic (p. 76)
• Delete a Topic (p. 77)
Create a Topic
The following command creates a topic:
{
"TopicArn": "arn:aws:sns:us-west-2:123456789012:MyTopic"
}
Make a note of the TopicArn, which you will use later to publish a message.
Subscribe to a Topic
The following command subscribes to a topic using the email protocol and an email address for the
notification endpoint:
75
AWS Command Line Interface User Guide
Publish to a Topic
{
"SubscriptionArn": "pending confirmation"
}
An email message will be sent to the email address listed in the subscribe command. The email message
will have the following text:
After clicking Confirm subscription, a "Subscription confirmed!" notification message should appear in
your browser with information similar to the following:
Subscription confirmed!
Publish to a Topic
The following command publishes a message to a topic:
{
"MessageId": "4e41661d-5eec-5ddf-8dab-2c867a709bab"
}
An email message with the text "Hello World!" will be sent to emailusername@example.com
76
AWS Command Line Interface User Guide
Delete a Topic
Delete a Topic
The following command deletes a topic:
For a list of commands and how to work with domains in Amazon SWF, see the following topics.
Topics
• List of Amazon SWF Commands by Category (p. 77)
• Working with Amazon SWF Domains Using the AWS Command Line Interface (p. 80)
For an alphabetic list of commands, see the Amazon SWF section of the AWS Command Line Interface
Reference, or use the following command.
To get help for a particular command, use the help directive after the command name. The following
shows an example.
Topics
• Commands Related to Activities (p. 78)
• Commands Related to Deciders (p. 78)
• Commands Related to Workflow Executions (p. 78)
• Commands Related to Administration (p. 78)
• Visibility Commands (p. 79)
77
AWS Command Line Interface User Guide
List of Amazon SWF Commands
• 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
• 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
78
AWS Command Line Interface User Guide
List of Amazon SWF Commands
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 Command Line Interface (p. 80).
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
• 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 Command Line Interface (p. 80).
79
AWS Command Line Interface User Guide
Working with Amazon SWF Domains
Topics
• Listing Your Domains (p. 80)
• Getting Information About a Domain (p. 81)
• Registering a Domain (p. 81)
• Deprecating a Domain (p. 82)
• See Also (p. 83)
Note
For an example of using DEPRECATED, see Deprecating a Domain (p. 82). As you might guess,
it returns any deprecated domains you have.
80
AWS Command Line Interface User Guide
Working with Amazon SWF Domains
}
],
"nextPageToken": "ANeXAMPLEtOKENiSpRETTYlONG=="
Note
The nextPageToken that is returned to you will be much longer. This value is merely an example
for illustrative purposes.
When you make the call again, this time supplying the value of nextPageToken in the
--next-page-token argument, you'll get another page of results:
When there are no further pages of results to retrieve, nextPageToken will not be returned in the results.
Registering a Domain
To register new domains, use swf register-domain. There are two required parameters, --name,
which takes the domain name, 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 will not be retained after the specified number of days have passed.
81
AWS Command Line Interface User Guide
Working with Amazon SWF Domains
When you register a domain, nothing is returned (""), but you can use swf list-domains or swf
describe-domain to see the new domain. For example:
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.
82
AWS Command Line Interface User Guide
Working with Amazon SWF Domains
"name": "mytest"
}
]
}
You can see deprecated domains by using --registration-status DEPRECATED with list-domains.
You can also use describe-domain to get information about a deprecated domain.
See Also
• deprecate-domain in the AWS Command Line Interface Reference
• describe-domain in the AWS Command Line Interface Reference
• list-domains in the AWS Command Line Interface Reference
• register-domain in the AWS Command Line Interface Reference
83
AWS Command Line Interface User Guide
The following table describes the important changes since the last release of the AWS Command Line
Interface User Guide.
New Tutorial Deploying a Development Environment in Amazon EC2 December 22, 2014
Using the AWS Command Line Interface (p. 23)
Rewrote Configura- Reorganized Configuring the AWS CLI (p. 11) to emphas- November 17, 2014
tion Instructions ize the quickest configuration path and sort instructions
by configuration method instead of setting. Moved some
topics to subpages.
New Sections Added a section to the Using Parameters page (p. 29) October 17, 2014
describing the standard parameter types. Added a section
to the Getting Help page (p. 27) describing the API refer-
ences and their use. Various minor corrections and
formatting updates.
Updated Document- The introduction (p. 1) and getting started (p. 3) sections May 26, 2014
ation have been reworked, and guidance has been updated with
information about the default credential provider chain.
Update Updated instructions for getting set up. For more informa- October 15, 2013
tion, see Getting Set Up (p. 3).
Update Added information about using Amazon SWF commands. September 20, 2013
For more information, see Using Amazon Simple Workflow
Service with the AWS Command Line Interface (p. 77).
General release This is the general release of the AWS Command Line September 3, 2013
Interface User Guide.
84
AWS Command Line Interface User Guide
New developer pre- This is a developer preview of the AWS Command Line December 21, 2012
view guide Interface User Guide.
85