Cheatography
https://cheatography.com
The AWS CLI provides built-in JSON-based client-side filtering capabilities with the --query parameter. The --query parameter is a powerful tool you can use to customize the content and style of your output. The --query parameter takes the HTTP response that comes back from the server and filters the results before displaying them. Since the entire HTTP response is sent to the client before filtering, client-side filtering can be slower than server-side filtering for large data-sets.
This is a draft cheat sheet. It is a work in progress and is not finished yet.
Selecting from a list
Filter through all output from an array |
aws <command> <subcommand> --query '<arrayName>[*]'
aws ec2 describe-volumes --query 'Volumes[*]'
|
View a specific item in the array by index |
aws <command> <subcommand> --query '<arrayName>[<index>]'
aws ec2 describe-volumes --query 'Volumes[0]'
|
View a specific range of volumes by index |
aws <command> <subcommand> --query '<arrayName>[<start>:<stop>:<step>]'
aws ec2 describe-volumes --query 'Volumes[0:2:1]'
|
|
Flattening results
Flatten the results (remove asterisk) |
aws <command> <subcommand> --query '<arrayName>[]
aws ec2 describe-volumes --query 'Volumes[*].Attachments[].State'
|
|
Filtering nested data
Narrow the filtering for nested values |
aws <command> <subcommand> --query '<expression>.<expression>'
aws ec2 describe-volumes --query 'Volumes[*].Attachments[*].State'
|
|
Intro
No filtering |
aws <command> <subcommand>
|
Filtering |
aws <command> <subcommand> --query 'YOUR_QUERY'
|
Filtering for specific values
Filter for specific values in a list |
aws <command> <subcommand> --query '<arrayName>[? <expression> <comparator> <expression>]]'
aws ec2 describe-volumes --query 'Volumes[*].Attachments[?State==`attached`].VolumeId'
|
|