AWS CLI starts with query

· Thomas Taylor

If a user wants to search AWS resources using a starts_with or “begins with” or “has prefix” query, the AWS CLI natively supports it.

How to query using starts_with

Using AWS CloudFormation as an example, the AWS CLI allows for the following query syntax:

1export prefix="<prefix>"
2aws cloudformation describe-stacks \
3	--query "Stacks[?starts_with(StackName, `$prefix`) == `true`].StackName"

This outputs all of the CloudFormation stack names that start with a particular prefix.


The starts_with syntax is included in the JMESPath specification.

1boolean starts_with(string $subject, string $prefix)

Returns true if the $subject starts with the $prefix, otherwise this function returns false.

#aws   #aws-cli  

Reply to this post by email ↪