A path picks the same field from every item. Often you want only some items, or several fields of each.
Only the items that match
sh
aws ec2 describe-availability-zones --query "AvailabilityZones[?ZoneName=='us-east-1b'].ZoneId" --output text[?test] keeps the items for which the test is true. ZoneName=='us-east-1b' compares a field with a value; the value sits in single quotes, inside the double quotes that keep the shell away.
AvailabilityZones
| ZoneName | ZoneId |
|---|---|
| us-east-1a | use1-az1 |
| us-east-1b | use1-az2 |
| us-east-1c | use1-az3 |
A test can also check how a value starts: [?starts_with(RegionName, 'eu')] keeps the regions whose names start with eu.
The first item
sh
aws ec2 describe-regions --query "Regions[0].RegionName"[0] is the first item, [1] the second. [] is every item.
Several fields of each item
sh
aws ec2 describe-availability-zones --query "AvailabilityZones[].[ZoneName,ZoneId]" --output texttext
us-east-1a use1-az1
us-east-1b use1-az2
us-east-1c use1-az3Field names in square brackets after an item give one row per item, one column per field. With --output table you get the same rows in boxes.