Advertisement
Intermediate AWS, AWS CLI & SDKs

How does the AWS CLI support output formatting and filtering results using JMESPath queries?

Short answer

The AWS CLI supports multiple output formats including JSON, table, and text, and it also supports the --query flag, which uses JMESPath syntax to filter and reshape the output directly at the command line, letting you extract exactly the specific fields you need from a large…

Save AWS mock interview
Advertisement
AModel answer
The AWS CLI supports multiple output formats including JSON, table, and text, and it also supports the --query flag, which uses JMESPath syntax to filter and reshape the output directly at the command line, letting you extract exactly the specific fields you need from a large, complex API response without needing to pipe the output into a separate tool for parsing.
Example

aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId,State.Name]' --output table

Real-world example
A systems administrator uses a JMESPath query directly within an AWS CLI command to quickly extract just the instance IDs and current states of all running EC2 instances, without needing to manually parse through a large raw JSON response.
Likely follow-ups
  • What is JMESPath and where else is it used within the AWS ecosystem?
  • How do you combine --query with --output text for use in shell scripts?
Related topics