Reputation: 157
I want to publish a notification using SNS and I want subscribers to be able to filter on multiple message attribute(s). One of such message attribute is going to be a String.Array. For example, the notification can have two attributes fruit_found and all_fruits_found.
"fruit_found": ["Apple"],"all_fruits_found":["Mango","Apple","Banana"]
There can be use cases where a subscriber might need to know if both Mango and Apple were found and only then consume the notification else drop it. Is it possible to do so in SNS?
Upvotes: 4
Views: 2752
Reputation: 157
So I had to talk to the SNS customer support team and found out that they don't have AND operation within a String.array message attributes.
A workaround that I found was to replicate the same message attributes for the number of filters you want to provide. For the message in the question, it should have structure like:
"fruit_found": ["Apple"],
"all_fruits_found_filter_1":["Mango","Apple","Banana"],
"all_fruits_found_filter_2":["Mango","Apple","Banana"]
The filter policy defined for when both Mango and Apple are found would be:
"all_fruits_found_filter_1": ["Mango"] //and
"all_fruits_found_filter_2": ["Apple"]
However, there is a limitation of at max 10 message attributes per SNS message. So if you are within that boundary the above solution works fine. Else you would have to refer to the answer from Ali.
Upvotes: 3
Reputation: 434
You cannot achieve this using SNS alone you might require a lambda function to receive SNS message and separate it based on the string and publish again to a topic.
You might need to create three SNS topic:
Upvotes: 0