When should you use the AWS CLI's `--query` instead of piping to `jq`?
IntermediateConceptfind, xargs, jq and yq
Answer
--query uses JMESPath and runs inside the CLI, so there is no extra dependency, and --output text gives tab-separated values ready for read.
aws ec2 describe-instances \
--filters Name=tag:Env,Values=prod Name=instance-state-name,Values=running \
--query 'Reservations[].Instances[].[InstanceId,PrivateIpAddress]' --output text |
while read -r id ip; do echo "$id $ip"; done
Use jq for complex transformations, joins, or when the same script handles output from other tools. kubectl has a similar option with -o jsonpath='{.items[*].metadata.name}'.
More on find, xargs, jq and yq
What are the most useful `find` predicates for operations work?BeginnerWhat is the difference between `-exec cmd {} \;`, `-exec cmd {} +` and `-delete`?IntermediateHow does `find` evaluate `-o` (OR) and why do you need parentheses?AdvancedWhat does `xargs` do, and which flags matter?IntermediateWhy is `find | xargs rm` dangerous and what is the safe form?IntermediateWhat is `jq` and what are the filters you use every day?Beginner