Search code examples
amazon-web-servicesamazon-sns

Filtering AWS SNS messages by attribute value but only if attribute is present


I would like to know how I can create a filtering policy for AWS SNS subscription that would check a message attribute value but only if that attribute is present. By default if I check an attribute value but attribute is not present message is ignored e.g:

"customer_interests": ["paintball"]

I also found this for attribute presence checking:

"customer_interests": [{"exists": true}]

But I'm not sure how to combine this two checks into a single policy.

I've tried the obvious thing:

{
   "customer_interests": [{"exists": false}, "paintball"]
}

but it doesn't work.


Solution

  • i have tried the following thing ( your obvious thing ) and it worked for me, i didn't have to even wait for 15 minutes (clearly eventual consistency is not the issue )

    Used the following policy

    {
      "customer_interests": [
        {
          "exists": false
        },
        "paintball"
      ]
    }
    
    • Created a sns topic with email-based subscription
    • added filter policy to subscriber

    tried with three use case

    Case 1

    • message hello
    • attribute type string
    • atrribute name customer_interests
    • atrribute value paintball
    • status recieved

    Case 3

    • message hello
    • attribute type string
    • atrribute name customer_interests
    • atrribute value xyz
    • status not recieved

    Case 3

    • message hello
    • attribute type string
    • atrribute name jatin
    • atrribute value test
    • status recieved