AWS Command Line Interface

[Pages:240]AWS Command Line Interface

User Guide for Version 2

AWS Command Line Interface User Guide for Version 2

AWS Command Line Interface: User Guide for Version 2

Copyright ? 2023 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 for Version 2

Table of Contents

...................................................................................................................................................... vii About the AWS CLI ............................................................................................................................ 1

About AWS CLI version 2 ............................................................................................................ 1 Maintenance and support for SDK major versions .......................................................................... 2 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 AWS CLI install and update instructions ................................................................................ 7 Troubleshooting AWS CLI install and uninstall errors ............................................................. 15 Next steps ....................................................................................................................... 15 Past releases ............................................................................................................................ 15 Troubleshooting AWS CLI install and uninstall errors ............................................................. 27 Next steps ....................................................................................................................... 27 Amazon ECR Public/Docker ....................................................................................................... 27 Prerequisites .................................................................................................................... 27 Deciding between Amazon ECR Public and Docker Hub ......................................................... 27 Run the official images ..................................................................................................... 28 Notes on interfaces and backwards compatibility of the official images ................................... 29 Use specific versions and tags ............................................................................................ 29 Update to the latest official image ..................................................................................... 30 Share host files, credentials, environment variables, and configuration .................................... 30 Shorten the docker run command ...................................................................................... 34 Quick setup ............................................................................................................................. 36 New configuration quick setup ........................................................................................... 37 Using existing configuration and credentials files ................................................................. 37 Configuring the AWS CLI ................................................................................................................... 38 Configuration basics ................................................................................................................. 38 Quick configuration with aws configure .......................................................................... 39 Access key ID and secret access key .................................................................................... 39 Region ............................................................................................................................ 41 Output format ................................................................................................................. 41 Profiles ........................................................................................................................... 41 Configuration settings and precedence ................................................................................ 42 Configuration and credential file settings .................................................................................... 42 Where are configuration settings stored? ............................................................................. 42 Set and view configuration settings .................................................................................... 43 Supported config file settings ......................................................................................... 45 Named profiles ........................................................................................................................ 55 Creating named profiles .................................................................................................... 55 Using named profiles ........................................................................................................ 56 AWS IAM Identity Center (successor to AWS Single Sign-On) .......................................................... 56 Configure automatic token refresh ..................................................................................... 57 Configure legacy non-refreshable ....................................................................................... 61 Using AWS IAM Identity Center (successor to AWS Single Sign-On) ......................................... 64 Environment Variables .............................................................................................................. 67

iii

AWS Command Line Interface User Guide for Version 2

How to set environment variables ...................................................................................... 67 AWS CLI supported environment variables ........................................................................... 68 Command line options .............................................................................................................. 72 How to use command line options ..................................................................................... 72 AWS CLI supported global command line options ................................................................. 72 Common uses of command line options .............................................................................. 75 Command completion ............................................................................................................... 76 How it works ................................................................................................................... 76 Configuring command completion on Linux or macOS .......................................................... 76 Configuring command completion on Windows .................................................................... 79 Retries .................................................................................................................................... 80 Available retry modes ....................................................................................................... 80 Configuring a retry mode .................................................................................................. 82 Viewing logs of retry attempts .......................................................................................... 83 External credentials .................................................................................................................. 83 Using credentials for Amazon EC2 instance metadata ................................................................... 84 Prerequisites .................................................................................................................... 85 Configuring a profile for Amazon EC2 metadata ................................................................... 85 Using an HTTP proxy ................................................................................................................ 86 Using the examples .......................................................................................................... 86 Authenticating to a proxy .................................................................................................. 87 Using a proxy on Amazon EC2 instances ............................................................................. 87 Using IAM roles ........................................................................................................................ 87 Prerequisites .................................................................................................................... 88 Overview of using IAM roles .............................................................................................. 88 Configuring and using a role ............................................................................................. 89 Using MFA ....................................................................................................................... 90 Cross-account roles and external ID .................................................................................... 91 Specifying a role session name for easier auditing ................................................................ 91 Assume role with web identity ........................................................................................... 92 Clearing cached credentials ............................................................................................... 93 Using the AWS CLI ........................................................................................................................... 94 Getting Help ............................................................................................................................ 94 The built-in AWS CLI help command ................................................................................... 94 AWS CLI reference guide ................................................................................................... 98 API documentation ........................................................................................................... 98 Troubleshooting errors ...................................................................................................... 98 Additional help ................................................................................................................ 98 Command Structure ................................................................................................................. 98 Command structure .......................................................................................................... 99 Wait commands ............................................................................................................... 99 Specifying Parameter Values .................................................................................................... 100 Common Parameter Types ............................................................................................... 101 Quotes with Strings ........................................................................................................ 104 Parameters from Files ..................................................................................................... 107 Generating a CLI Skeleton Template ................................................................................. 109 Shorthand Syntax ........................................................................................................... 117 Auto-prompt .......................................................................................................................... 119 How it works ................................................................................................................. 119 Auto-prompt features ..................................................................................................... 119 Auto-prompt modes ....................................................................................................... 121 Configure auto-prompt ................................................................................................... 122 Controlling Command Output .................................................................................................. 122 Output Format ............................................................................................................... 122 Pagination ..................................................................................................................... 128 Filtering ......................................................................................................................... 132 Return Codes ......................................................................................................................... 148

iv

AWS Command Line Interface User Guide for Version 2

Wizards ................................................................................................................................. 149 How it works ................................................................................................................. 150

Aliases ................................................................................................................................... 150 Prerequisites .................................................................................................................. 151 Step 1: Creating the alias file ........................................................................................... 151 Step 2: Creating an alias ................................................................................................. 152 Step 3: Calling an alias .................................................................................................... 154 Alias repository examples ................................................................................................ 155 Resources ...................................................................................................................... 156

Using the AWS CLI with AWS Services ............................................................................................... 157 DynamoDB ............................................................................................................................. 157 Prerequisites .................................................................................................................. 158 Creating and using DynamoDB tables ............................................................................... 158 Using DynamoDB Local ................................................................................................... 159 Resources ...................................................................................................................... 159 Amazon EC2 .......................................................................................................................... 160 Amazon EC2 Key Pairs .................................................................................................... 160 Amazon EC2 Security Groups ........................................................................................... 163 EC2 Instances ................................................................................................................. 166 Change EC2 type using bash scripting ............................................................................... 171 S3 Glacier .............................................................................................................................. 173 Prerequisites .................................................................................................................. 173 Create an Amazon S3 Glacier vault ................................................................................... 174 Prepare a file for uploading ............................................................................................. 174 Initiate a multipart upload and upload files ....................................................................... 174 Complete the upload ...................................................................................................... 175 Resources ...................................................................................................................... 177 IAM ....................................................................................................................................... 177 Creating IAM users and groups ......................................................................................... 178 Attaching an IAM managed policy to an IAM user ............................................................... 179 Setting an initial password for an IAM user ........................................................................ 180 Create an access key for an IAM user ................................................................................ 180 Amazon S3 ............................................................................................................................ 181 High-level (s3) commands ............................................................................................... 181 API-level (s3 api) commands ............................................................................................ 189 Bucket lifecycle scripting example (s3api) ......................................................................... 191 Amazon SNS .......................................................................................................................... 193 Create a topic ................................................................................................................ 194 Subscribe to a topic ........................................................................................................ 194 Publish to a topic ........................................................................................................... 195 Unsubscribe from a topic ................................................................................................ 195 Delete a topic ................................................................................................................ 195 Amazon SWF ......................................................................................................................... 195 List of Amazon SWF Commands ....................................................................................... 196 Working with Amazon SWF Domains ................................................................................ 198

Security ......................................................................................................................................... 201 Data Protection ...................................................................................................................... 201 Data encryption ............................................................................................................. 202 Identity and Access Management .............................................................................................. 202 Compliance Validation ............................................................................................................. 203 Enforcing a minimum TLS version ............................................................................................ 203

Troubleshooting errors .................................................................................................................... 204 General troubleshooting to try first .......................................................................................... 204 Check your AWS CLI command formatting ......................................................................... 204 Confirm that you're running a recent version of the AWS CLI ................................................ 205 Use the --debug option ................................................................................................. 205 Enable and review the AWS CLI command history logs ........................................................ 209

v

AWS Command Line Interface User Guide for Version 2

Confirm that your AWS CLI is configured ........................................................................... 209 Command not found errors ..................................................................................................... 209 The "aws --version" command returns a different version than you installed .............................. 211 The "aws --version" command returns a version after uninstalling the AWS CLI .......................... 212 The AWS CLI processed a command with an incomplete parameter name ...................................... 213 Access denied errors ............................................................................................................... 213 Invalid credentials and key errors ............................................................................................. 214 Signature does not match errors .............................................................................................. 215 SSL certificate errors ............................................................................................................... 216 Invalid JSON errors ................................................................................................................. 217 Additional resources ................................................................................................................ 218 Migration guide .............................................................................................................................. 219 New features and changes ....................................................................................................... 219

AWS CLI version 2 new features ....................................................................................... 219 Breaking changes between AWS CLI version 1 and AWS CLI version 2 .................................... 220 Migration instructions ............................................................................................................. 225 Replacing version 1 with version 2 .................................................................................... 226 Side-by-side install ......................................................................................................... 226 Uninstall ........................................................................................................................................ 227 Troubleshooting AWS CLI install and uninstall errors ................................................................... 229 Document History .......................................................................................................................... 230 AWS glossary ................................................................................................................................. 233

vi

AWS Command Line Interface User Guide for Version 2 vii

AWS Command Line Interface User Guide for Version 2 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 Migrating from AWS CLI version 1 to version 2 (p. 219).

The AWS CLI version 2 is available to install only as a bundled installer. While you might 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).

To check the currently installed version, use the following command:

$ aws --version aws-cli/2.7.24 Python/3.8.8 Linux/4.14.133-113.105.amzn2.x86_64 botocore/1.13

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

1

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

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

Google Online Preview   Download