AWS Command Line Interface

[Pages:215]AWS Command Line Interface

User Guide

AWS Command Line Interface User Guide

AWS Command Line Interface: User Guide

Copyright ? Amazon Web Services, Inc. and/or its affiliates. All rights reserved. Amazon's trademarks and trade dress may not be used in connection with any product or service that is not Amazon's, in any manner that is likely to cause confusion among customers, or in any manner that disparages or discredits Amazon. All other trademarks not owned by Amazon are the property of their respective owners, who may or may not be affiliated with, connected to, or sponsored by Amazon.

AWS Command Line Interface User Guide

Table of Contents

...................................................................................................................................................... vii What Is the AWS CLI? ......................................................................................................................... 1

About AWS CLI version 2 ............................................................................................................ 1 Maintenance and support for SDK major versions .......................................................................... 1 About Amazon Web Services ....................................................................................................... 2 Using the examples .................................................................................................................... 2 Additional documentation and resources ....................................................................................... 3

AWS CLI documentation and resources ................................................................................. 3 Other AWS SDKs ................................................................................................................ 3 Getting started .................................................................................................................................. 4 Prerequisites .............................................................................................................................. 4 Step 1: Sign up to AWS ...................................................................................................... 4 Step 2: Create an IAM user account ...................................................................................... 4 Step 3: Create an access key ID and secret access key ............................................................. 5 Next steps ......................................................................................................................... 6 Install/Update ............................................................................................................................ 6 Next steps ....................................................................................................................... 15 Past releases ............................................................................................................................ 15 Next steps ....................................................................................................................... 25 Docker .................................................................................................................................... 25 Prerequisites .................................................................................................................... 25 Run the official Docker image ............................................................................................ 25 Notes on interfaces and backwards compatibility of Docker image .......................................... 26 Use specific versions and tags ............................................................................................ 26 Update to the latest Docker image ..................................................................................... 27 Share host files, credentials, environment variables, and configuration .................................... 27 Shorten the Docker command ........................................................................................... 29 Add to path ............................................................................................................................. 30 Quick setup ............................................................................................................................. 31 New configuration quick setup ........................................................................................... 32 Using existing configuration and credentials files ................................................................. 32 Configuring the AWS CLI ................................................................................................................... 33 Configuration basics ................................................................................................................. 33 Quick configuration with aws configure .......................................................................... 34 Access key ID and secret access key .................................................................................... 34 Region ............................................................................................................................ 35 Output format ................................................................................................................. 35 Profiles ........................................................................................................................... 36 Configuration settings and precedence ................................................................................ 36 Configuration and credential file settings .................................................................................... 37 Where are configuration settings stored? ............................................................................. 37 Set and view configuration settings .................................................................................... 38 Supported config file settings ......................................................................................... 39 Named profiles ........................................................................................................................ 49 Using profiles with the AWS CLI ......................................................................................... 49 Configuring the AWS CLI to use AWS Single Sign-On .................................................................... 50 Configuring a named profile to use AWS SSO ...................................................................... 50 Using an AWS SSO enabled named profile .......................................................................... 53 Environment Variables .............................................................................................................. 55 How to set environment variables ...................................................................................... 56 AWS CLI supported environment variables ........................................................................... 56 Command line options .............................................................................................................. 60 Command completion ............................................................................................................... 63 How it works ................................................................................................................... 63

iii

AWS Command Line Interface User Guide

Configuring command completion on Linux or macOS .......................................................... 63 Configuring command completion on Windows .................................................................... 66 Verify command completion .............................................................................................. 66 Retries .................................................................................................................................... 66 Available retry modes ....................................................................................................... 67 Configuring a retry mode .................................................................................................. 68 Viewing logs of retry attempts .......................................................................................... 69 Sourcing credentials with an external process .............................................................................. 70 Using credentials for Amazon EC2 instance metadata ................................................................... 71 Prerequisites .................................................................................................................... 71 Configuring a profile for Amazon EC2 metadata ................................................................... 71 Using an HTTP proxy ................................................................................................................ 72 Authenticating to a proxy .................................................................................................. 73 Using a proxy on Amazon EC2 instances ............................................................................. 73 Using an IAM role in the AWS CLI .............................................................................................. 73 Configuring and using a role ............................................................................................. 74 Using MFA ....................................................................................................................... 76 Cross-account roles and external ID .................................................................................... 77 Specifying a role session name for easier auditing ................................................................ 77 Assume role with web identity ........................................................................................... 78 Clearing cached credentials ............................................................................................... 79 Using the AWS CLI ........................................................................................................................... 80 Getting Help ............................................................................................................................ 80 AWS CLI documentation .................................................................................................... 83 API documentation ........................................................................................................... 83 Additional help ................................................................................................................ 84 Command Structure ................................................................................................................. 84 Command structure .......................................................................................................... 84 Wait commands ............................................................................................................... 85 Specifying Parameter Values ...................................................................................................... 86 Common Parameter Types ................................................................................................. 86 Quotes with Strings .......................................................................................................... 89 Parameters from Files ....................................................................................................... 92 Generating a CLI Skeleton Template ................................................................................... 94 Shorthand Syntax ........................................................................................................... 102 Auto-prompt .......................................................................................................................... 103 How it works ................................................................................................................. 103 Auto-prompt features ..................................................................................................... 104 Auto-prompt modes ....................................................................................................... 106 Configure auto-prompt ................................................................................................... 106 Controlling Command Output .................................................................................................. 106 Output Format ............................................................................................................... 106 Pagination ..................................................................................................................... 113 Filtering ......................................................................................................................... 117 Return Codes ......................................................................................................................... 133 Wizards ................................................................................................................................. 134 How it works ................................................................................................................. 134 Aliases ................................................................................................................................... 135 Prerequisites .................................................................................................................. 135 Step 1: Creating the alias file ........................................................................................... 135 Step 2: Creating an alias ................................................................................................. 136 Step 3: Calling an alias .................................................................................................... 137 Alias repository examples ................................................................................................ 139 Resources ...................................................................................................................... 139 Using the AWS CLI with AWS Services ............................................................................................... 141 DynamoDB ............................................................................................................................. 141 Prerequisites .................................................................................................................. 141

iv

AWS Command Line Interface User Guide

Creating and using DynamoDB tables ............................................................................... 142 Using DynamoDB Local ................................................................................................... 143 Resources ...................................................................................................................... 143 Amazon EC2 .......................................................................................................................... 143 Amazon EC2 Key Pairs .................................................................................................... 144 Amazon EC2 Security Groups ........................................................................................... 146 EC2 Instances ................................................................................................................. 151 Change EC2 type using bash scripting ............................................................................... 157 S3 Glacier .............................................................................................................................. 159 Create an Amazon S3 Glacier vault ................................................................................... 159 Prepare a file for uploading ............................................................................................. 160 Initiate a multipart upload and upload files ....................................................................... 160 Complete the upload ...................................................................................................... 161 IAM ....................................................................................................................................... 163 Creating IAM users and groups ......................................................................................... 163 Attaching an IAM managed policy to an IAM user ............................................................... 164 Setting an initial password for an IAM user ........................................................................ 165 Create an access key for an IAM user ................................................................................ 165 Amazon S3 ............................................................................................................................ 166 High-level (s3) commands ............................................................................................... 166 API-level (s3 api) commands ............................................................................................ 174 Bucket lifecycle scripting example (s3api) ......................................................................... 176 Amazon SNS .......................................................................................................................... 178 Create a topic ................................................................................................................ 179 Subscribe to a topic ........................................................................................................ 179 Publish to a topic ........................................................................................................... 179 Unsubscribe from a topic ................................................................................................ 180 Delete a topic ................................................................................................................ 180 Amazon SWF ......................................................................................................................... 180 List of Amazon SWF Commands ....................................................................................... 181 Working with Amazon SWF Domains ................................................................................ 183 Security ......................................................................................................................................... 186 Data Protection ...................................................................................................................... 186 Data encryption ............................................................................................................. 187 Identity and Access Management .............................................................................................. 187 Compliance Validation ............................................................................................................. 188 Enforcing TLS 1.2 ................................................................................................................... 188 Troubleshooting Errors .................................................................................................................... 189 General: Ensure you're running a recent version of the AWS CLI. ................................................... 189 General: Use the --debug option. ............................................................................................ 189 I get the error "command not found" when I run aws. ................................................................. 193 Possible cause: The operating system "path" was not updated during installation. ................... 193 I get "access denied" errors. ..................................................................................................... 193 Possible cause: The AWS CLI program file doesn't have "run" permission. ............................... 193 Possible cause: Your IAM identity doesn't have permission to perform the operation. ............... 194 I get an "invalid credentials" error. ............................................................................................ 194 Possible cause: The AWS CLI is reading credentials from an unexpected location. ..................... 194 Possible cause: Your computer's clock is out of sync. ........................................................... 194 I get a "signature does not match" error. ................................................................................... 195 Possible cause: Your clock is out of sync with the AWS servers. ............................................. 195 Possible cause: Your operating system is mishandling AWS secret keys that contain certain special characters. .......................................................................................................... 195 I get a "No Windows console found. Are you running cmd.exe?" error. ............................................ 196 I get a "[SSL: CERTIFICATE_ VERIFY_FAILED] certificate verify failed" error. ..................................... 196 Additional resources ................................................................................................................ 196 Migrating/Breaking Changes ............................................................................................................ 197 File encoding environment variable .......................................................................................... 197

v

AWS Command Line Interface User Guide Passing binary parameters ....................................................................................................... 197 Improved Amazon S3 property and tag handling during s3 copy operations ................................. 198 No automatic retrieval of webpages for parameters .................................................................... 199 Output paging ....................................................................................................................... 199 All date/time values in ISO 8601 format ................................................................................... 200 Improved AWS CloudFormation deployment handling ................................................................. 200 Amazon S3 and us-east-1 Region ............................................................................................. 201 AWS STS and regional endpoints .............................................................................................. 201 Deprecate ecr get-login .................................................................................................... 201 Changing support for [plugins] ............................................................................................ 202 No hidden aliases ................................................................................................................... 202 No longer supports api_versions .......................................................................................... 203 Uninstall ........................................................................................................................................ 204 Document History .......................................................................................................................... 206

vi

AWS Command Line Interface User Guide vii

AWS Command Line Interface User Guide About AWS CLI version 2

What is the AWS Command Line Interface?

The AWS Command Line Interface (AWS CLI) is an open source tool that enables you to interact with AWS services using commands in your command-line shell. With minimal configuration, the AWS CLI enables you to start running commands that implement functionality equivalent to that provided by the browser-based AWS Management Console from the command prompt in your terminal program:

? Linux shells ? Use common shell programs such as bash, zsh, and tcsh to run commands in Linux or macOS.

? Windows command line ? On Windows, run commands at the Windows command prompt or in PowerShell.

? Remotely ? Run commands on Amazon Elastic Compute Cloud (Amazon EC2) instances through a remote terminal program such as PuTTY or SSH, or with AWS Systems Manager.

All IaaS (infrastructure as a service) AWS administration, management, and access functions in the AWS Management Console are available in the AWS API and AWS CLI. New AWS IaaS features and services provide full AWS Management Console functionality through the API and CLI at launch or within 180 days of launch.

The AWS CLI provides direct access to the public APIs of AWS services. You can explore a service's capabilities with the AWS CLI, and develop shell scripts to manage your resources. In addition to the low-level, API-equivalent commands, several AWS services provide customizations for the AWS CLI. Customizations can include higher-level commands that simplify using a service with a complex API.

About AWS CLI version 2

The AWS CLI version 2 is the most recent major version of the AWS CLI and supports all of the latest features. Some features introduced in version 2 are not backported to version 1 and you must upgrade to access those features. There are some "breaking" changes from version 1 that might require you to change your scripts. For a list of breaking changes in version 2, see Breaking changes ? Migrating from AWS CLI version 1 to version 2 (p. 197).

The AWS CLI version 2 is available to install only as a bundled installer. While you may find it in package managers, these are unsupported and unofficial packages that are not produced or managed by AWS. We recommend that you install the AWS CLI from only the official AWS distribution points, as documented in this guide.

To install the AWS CLI version 2, see the section called "Install/Update" (p. 6).

For version history, see the AWS CLI version 2 Changelog on GitHub.

Maintenance and support for SDK major versions

For information about maintenance and support for SDK major versions and their underlying dependencies, see the following in the AWS SDKs and Tools Reference Guide:

1

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download