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

1 Answers1

0

Context

  • Jmespath query on AWS shell

Problem

  • How to specify or-expression over a string-contains query

Solution

  • change BEFORE into AFTER

Before

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

After

 Stacks[? (contains(StackName, 'STRING_A') || contains(StackName, 'STRING_B')) ]
dreftymac
  • 31,404
  • 26
  • 119
  • 182