List and filter AWS topics in Powershell

48 Views Asked by At

I'm trying to list all the sns topics that contain local, in a powershell script

I've got this working (finally):

aws sns list-topics --query 'Topics[?contains(TopicArn, `local`)].TopicArn' 

Now I want to replace 'local' with a variable

aws sns list-topics --query 'Topics[?contains(TopicArn, $prefix)].TopicArn' 

But this doesn't work because the --query parameter expects the filter to be surrounded by back ticks. Also, the whole query parameter needs to be surrounded by single ticks, not double quotes.

How can I achieve this?

1

There are 1 best solutions below

0
user459872 On BEST ANSWER

You could format the --query with format operator(-f).

$ aws sns list-topics --query ('Topics[?contains(TopicArn, `{0}`)].TopicArn' -f $prefix)