AWS CLI - 获取名称以字符串开头的所有 CloudFormation 堆栈

dem*_*ron 2 amazon-web-services aws-cloudformation aws-cli jmespath

我应该使用什么查询来获取以特定字符串开头的所有 CloudFormation 堆栈?

我尝试了以下查询,但它总是返回一个空数组:

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

我们帐户中的所有堆栈都以“HD-”开头,因此这应该返回与

aws cloudformation describe-stacks --no-paginate
Run Code Online (Sandbox Code Playgroud)

但它返回

[]
Run Code Online (Sandbox Code Playgroud)

dem*_*ron 6

这个命令工作正常:

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

看起来您需要在查询中使用 ` 而不是 ' 。