Notes to Self

Alex Sokolsky's Notes on Computers and Programming

AWS CLI Client

Sources:

Install

Following instructions:

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install

Enable auto complete - I added these to my .zshrc:

autoload bashcompinit && bashcompinit
autoload -Uz compinit && compinit
complete -C '/usr/local/bin/aws_completer' aws

Use

Verify the version:

$ aws --version
aws-cli/2.4.29 Python/3.8.8 Linux/5.13.0-37-generic exe/x86_64.linuxmint.20 prompt/off

or on Windows:

PS C:\Users\asoko> aws --version
aws-cli/2.5.2 Python/3.9.11 Windows/10 exe/AMD64 prompt/off

Configure, e.g. for local use:

PS C:\Users\asoko> aws configure
AWS Access Key ID [None]: keyid
AWS Secret Access Key [None]: accesskey
Default region name [None]: us-west-1
Default output format [None]:

Pagination

Note we are talking here about two entities:

It helps me to disable pagination in ~/.aws/credentials:

[default]
cli_pager=

or just

export AWS_PAGER=''

Environment Variables

https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html

Controlling command output

Topics:

$ aws ec2 describe-volumes --profile dev --output table \
    --no-cli-pager \
    --query 'sort_by(Volumes, &VolumeId)[].{VolumeId: VolumeId, VolumeType: VolumeType, InstanceId: Attachments[0].InstanceId, State: Attachments[0].State}'
----------------------------------------------------------------------------
|                              DescribeVolumes                             |
+----------------------+-----------+-------------------------+-------------+
|      InstanceId      |   State   |        VolumeId         | VolumeType  |
+----------------------+-----------+-------------------------+-------------+
|  i-06253db1de27a1472 |  attached |  vol-0034927f6d89a987c  |  gp3        |
|  i-0c9e0188fe0105ed6 |  attached |  vol-0ad69e58bb689838e  |  gp2        |
|  i-081d9511ae174ebb2 |  attached |  vol-0cf1ecc29edae56d4  |  gp3        |
|  i-0c9e1235fe0666ed6 |  attached |  vol-0fbe38a5b1656f575  |  gp3        |
+----------------------+-----------+-------------------------+-------------+

More

Filtering

From cli-usage-filter:

e.g.:

aws ec2 describe-vpn-connections \
    --filter 'Name=vpn-connection-id,Values=vpn-176b7876' \
    --query 'VpnConnections[0].CustomerGatewayConfiguration'

More