AWS CLI and Output Filtering

I love the AWS CLI –query option.  It allows you to pull out the relevant data you are looking for and display it in a nice table format.

There are a couple different ways to determine what the correct query parameters are.

#1 – Run your command and parse through the JSON that is returned.  The JSON will show you exactly what element(s) you can query on.

Example: aws ec2 describe-instances –query ‘Reservations[*].Instances[*].[InstanceId, Monitoring.State]’ –output table

#2 – Review the AWS CLI documentation. (e.g. describe-instance-status)  On this page you will want to examine the “Output” section, which gives you the same information as #1, but with a different view.

awscli.png

Example: aws describe-instance-status –query ‘InstanceStatuses[*].AvailabilityZone’ –output table

Overall using the query option is pretty easy and at the same time pretty powerful!

AmazonWebservices_Logo.svg_