Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SNS filtering anything-but doesn't accept blank message-attribute

I have a filter for a SNS subscription (SQS) where I'm using this filtering:

{"source":[{"anything-but":"SOME_STRING"}]}

This works OK, except that sometimes I have messages going to the SNS that doesn't have any message-attribute called source, and before using the filter, this subscription without filter was taking it.

So, in conclusion, I would like to find a way where my filter takes the message if it doesn't have this "source" attribute or in case it have it, it should be anything-but SOME_STRING.

Thank you!

like image 727
jasf87 Avatar asked Oct 24 '18 02:10

jasf87


1 Answers

Your requirement is to filter and pass messages if:

  1. The source attribute is missing
  2. The source attribute exists and it should be anything-but SOME_STRING.

Amazon SNS Subscription policy accepts messages under the following conditions.

1) Each attribute name in a filter policy matches an attribute name assigned to the message.

2) For each matching attribute name, at least one match exists between the following:

--> the values of the attribute name in the filter policy

--> the message attributes

As you can see in the given documentation for SNS Subscription filter policies, any message that does not contain the filtering attribute, or if that attribute value does not meet the policy, the message will be rejected.

According to your example, you CANNOT filter and pass messages which does not contain the "source" attribute. But you can filter if the source attribute exists and it should be anything-but SOME_STRING.

Workaround for this.

Assuming that you have access to the message generating source, make sure that every message contains the attribute "source", before pushing it to SNS. Then you can easily filter out if it is anything-but SOME_STRING.

like image 78
Keet Sugathadasa Avatar answered Sep 30 '22 18:09

Keet Sugathadasa