1

I need to extract, from AWS CLOUDFORMATION, all the stacks that contain, within the name, a specific string. I use the following command from aws-shell

aws cloudformation describe-stacks --query "Stacks[?contains(StackName, 'STRING_A')][StackName,StackId]" --output text | tr '\t' ';'

and I'm able to extract all the info that I need.

The problem is that I need to search also another string (suppose STRING_B)...What is the correct command? How can I insert an OR condition into the "?contains" ?

I made several attempts, but none has been successful.

e.g.

aws cloudformation describe-stacks --query "Stacks[?contains(StackName, 'STRING_A'||'STRING_B')][StackName,StackId]" --output text | tr '\t' ';'

but this solution extract only the records that satisfy the first condition (STRING_A)

For my application, instead of "contain" I can also use "ends_with".....the problem/question is the same :-)

I appreciate your help, thank you in advance

4

1 回答 1

1

语境

  • AWS shell 上的 Jmespath 查询

问题

  • 如何指定or-expression包含字符串的查询

解决方案

  • 将之前更改为之后

 Stacks[?contains(StackName, 'STRING_A'||'STRING_B')]

 Stacks[? (contains(StackName, 'STRING_A') || contains(StackName, 'STRING_B')) ]
于 2019-03-23T01:43:21.713 回答