Search code examples
amazon-web-servicesaws-cloudformationaws-clijmespath

AWS CLI - Get all CloudFormation stacks that have a name that starts with string


What query should I use to get all CloudFormation stacks that start with a specific string?

I have tried the following query, but it always returns an empty array:

aws cloudformation describe-stacks --no-paginate --query "Stacks[?StackName!='null']|[?starts_with(StackName,'HD-') == 'true']"

All the stacks in our account start with "HD-", so this should return the same as

aws cloudformation describe-stacks --no-paginate

But it returns

[]

Solution

  • This command works fine:

    aws cloudformation describe-stacks --no-paginate --query \
      'Stacks[?StackName!=`null`]|[?contains(StackName, `Release`) == `true`].StackName'
    

    It looks like you need to use ` rather than ' inside the query..