AWS CLI Filter Output With Query & Filter Options

AWS CLI Filter Output With Query & Filter Options

This will be helpful to get specific output from AWS request command. There are two type of filters provided by AWS.
  • Filter Output on Client Side or Query Option
  • Filter Output On Server Side or Filter Option

The server side filter is much faster than and efficient filter than client side (Query) but query option provides robust feature for most of commands supported by AWS CLI as compare to filter option.

Note: AWS CLI is case sensitive framework.

Filter Output On Server Side or Filter Option:

For example, If we want to see detail of any specific instance detail like t2.micro instance using filter option we can use command below to filter it out.

>> aws ec2 describe-instances --filter Name=instance-type,Values=t2.micro

In this command Name=instance-type is the output field name on which we want to filter and Value=t2.micro is value of that field

Filter Output on Client Side or Query Option:

As there are some limitations in AWS filter option that, it is generally supported by 'list' and 'describe' command and not for all AWS commands. In this case the 'Query' option can help us to filter out large amount of data. AWS Query command is different than Filter option command, it runs on client side.

Lets see command below:

>> aws ec2 describe-regions --query 'Regions[?RegionName==`us-west-2`]'

Please note here query expression is enclosed in single quotes but value for inside expression using 'backquote' character(`). The query written in this expression is in specific format following JEMSPath specification.

If we run only below command

>> aws ec2 describe-regions 

It will show all the available regions supported by AWS, as of now AWS global infrastructure is spread across 16 AWS regions and in future it will increase across the world.

You can see in query example  command 'Regions [' is the parent field and [?RegionName is child field of region and value is 'us-west-2' which will be use for filter the output.

OutPut>>

[
{ "Endpoint":"ec2 us-west-2.amazonaws.com",
  "RegionName":"us-west-2"
}
]

The conclusion is Filter option is filter output on server side and hence it is more efficient however filter options has some limitations where as Query option supports universally by all CLI commands.

Watch Video:




Related Posts:

What is AWS CLI (Amazon web services command line interface )


AWS CLI Filter Output With Query & Filter Options AWS CLI Filter Output With Query & Filter Options Reviewed by Web Technology Funda on 4:08:00 AM Rating: 5

No comments

Free! Free!Free! Subscribe to Get Free PHP (Magento) tutorial Update in Your Inbox!!! Hurry Up!!!