'AWS SNS Filter Policy to String match none of the elements in the array

I referred Amazon SNS subscription filter policies documentation. There is something not clear to me if it is possible to do.

Suppose we have a message with attribute

labels: ["A", "B"]

Now a filter policy like this will match it

{
  labels": ["A", "C"]
}

But a filter policy like this will also match it

{
  labels": [{"anything-but": ["A", "C"]}]
}

because of "B"

What we are looking for is a way to create two policies that are mutually exclusive.

  • If A or C are present then trigger Lambda1
  • If none of A or C are present, then trigger Lambda2

Is this possible?



Solution 1:[1]

Your example doesn't seem possible. One workaround to achieve it is to use anything-but with a prefix. Like this:

{
  "labels": [
    {
      "anything-but": {
        "prefix": "someprefix-"
      }
    }
  ]
}

You have to change your first filter like this:

{
  labels": ["someprefix-A", "someprefix-C"]
}

Now labels: ["someprefix-A", "B"] will only match the first filter.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ?????? ??????