Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does SNS allow filtering based on presence of multiple values in String.array

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?

like image 602
Saurabh Avatar asked Oct 22 '25 18:10

Saurabh


1 Answers

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.

like image 184
Saurabh Avatar answered Oct 24 '25 08:10

Saurabh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!