My notes on AWS CLI.
Table of contents
Open Table of contents
What is AWS CLI?
- A tool that enables to interact with AWS Services using commands in your command-line shell.
- Direct access to the public APIs of AWS Services.
- You can develop scripts to manage your resources.
- It’s open source https://github.com/aws/aws-cli.
- The latest version is AWS CLI v2.
- Alternatively, you can also use the AWS CloudShell that is a browser-based, pre-authenticated shell. It can be launched directly from the AWS Management Console. This service is not available in all AWS regions.
Check the AWS CLI version
$ aws --version
aws-cli/2.7.32 Python/3.9.11 Darwin/19.6.0 exe/x86_64 prompt/off
AWS CLI Configuration & Named Profiles
- The default location for the AWS CLI configuration is the
.aws
directory inside your operating system’s Home directory. For Windows OS it is%UserProfile%
and for Unix-based systems, it is$HOME
or~
(tilde). - By default, the AWS CLI uses the
default
profile. - We can create and use additional named profiles by specifying the
--profile
option and assigning a name. Check the following example where it creates a new profile namedadmin
.
$ aws configure --profile admin
AWS Access Key ID [None]: AKIAI44QH8DHBEXAMPLE
AWS Secret Access Key [None]: je7MtGbClwBF/2Zp9Utk/h3yCo8nvbEXAMPLEKEY
Default region name [None]: us-east-1
Default output format [None]: text
Check this Named profiles for AWS CLI guide for more details.
Using named profile
- Use
--profile <profile-name>
option to use a named profile. - Set
AWS_PROFILE
environment variable if you intend to execute multiple commands with the same named profile.
$ export AWS_PROFILE=admin
Change output format
- Use
--output <output-format>
option to override the default format option set. - Supported format options are
json
,yaml
,yaml-stream
,text
, andtable
. - Set
AWS_DEFAULT_OUTPUT
environment variable if you intend to execute multiple commands with the same output format.
$ export AWS_DEFAULT_OUTPUT=json
References
- Getting Started Guide - https://aws.amazon.com/cli/
- AWS CLI Installation Guide - https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html
- AWS CLI Setup Guide - https://docs.aws.amazon.com/cli/latest/userguide/getting-started-quickstart.html
- AWS CLI Named Profiles - https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html
- List of AWS CLI Envrionment Variables - https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html