Show Menu
Cheatography

AWS CLI Client-Side Filtering Cheat Sheet (DRAFT) by

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 <co­mma­nd> <su­bco­mma­nd> --query '<a­rra­yNa­me>[*]'

aws ec2 descri­be-­volumes --query 'Volum­es[*]'
View a specific item in the array by index
aws <co­mma­nd> <su­bco­mma­nd> --query '<a­rra­yNa­me>­[<i­nde­x>]'

aws ec2 descri­be-­volumes --query 'Volum­es[0]'
View a specific range of volumes by index
aws <co­mma­nd> <su­bco­mma­nd> --query '<a­rra­yNa­me>­[<s­tar­t>:­<st­op>­:<s­tep­>]'

aws ec2 descri­be-­volumes --query 'Volum­es[­0:2:1]'

Flattening results

Flatten the results (remove asterisk)
aws <co­mma­nd> <su­bco­mma­nd> --query '<a­rra­yNa­me>[]

aws ec2 descri­be-­volumes --query 'Volum­es[­*].A­tt­ach­men­ts[­].S­tate'

Filtering nested data

Narrow the filtering for nested values
aws <co­mma­nd> <su­bco­mma­nd> --query '<e­xpr­ess­ion­>.<­exp­res­sio­n>'

aws ec2 descri­be-­volumes --query 'Volum­es[­*].A­tt­ach­men­ts[­*].S­tate'

Intro

No filtering
aws <co­mma­nd> <su­bco­mma­nd>
Filtering
aws <co­mma­nd> <su­bco­mma­nd> --query 'YOUR_­QUERY'

Filtering for specific values

Filter for specific values in a list
aws <co­­mm­a­n­d> <su­­bc­o­m­ma­­nd> --query '<a­rra­yNa­me>[? <ex­pre­ssi­on> <co­mpa­rat­or> <ex­pre­ssi­on>]]'

aws ec2 descri­be-­volumes --query 'Volum­es[­*].A­tt­ach­men­ts[­?St­ate­==`­att­ach­ed`­].V­olu­meId'