Endrju
Endrju

Reputation: 353

Why AWS SNS filtering doesn't ignore unknown message attributes?

The AWS documentation says that unknown message attributes are ignored by filter policy.

When Amazon SNS evaluates message attributes against the subscription filter policy, it ignores message attributes that aren't specified in the policy.

However, it seems to be incorrect. Let's say I have such policy:

{
    "customer_interests": ["rugby"]
}

but message with additional attribute, for example:

   "MessageAttributes": {
      "customer_interests": {
         "Type": "String.Array",
         "Value": "[\"rugby\"]"
      },
      "request_id": {
         "Type": "String",
         "Value":"123456"
      }
   }

is rejected, even though customer_interests value is correct. I tested it on different params and whenever I add a field that particular policy doesn't except, the message is rejected. Can someone explain to me this behaviour?

Upvotes: 2

Views: 1447

Answers (2)

Zahid Khan
Zahid Khan

Reputation: 3267

AWS Documentation:

If any single property in this policy doesn't match an attribute assigned to the message, the policy rejects the message.

Ref: Amazon SNS example filter policies.

FIX TO THE PROBLEM

So, if your SNS Subscription filter policy is like:

{
  "requestId": [
    "1234"
  ]
}

The requestId attribute in your MessageAttributes should have its Type set to String, not String.Array:


 "MessageAttributes": {
      "requestId": {
         "Type": "String",
         "Value":"1234"
      },
      "customer_interests": {
         "Type": "String",
         "Value": "anything random"
      },
   }

The subscription filter policy will only consider the attributes you specify. Any other attributes, such as customer_interests that's in the message will be ignored during filtering.

Upvotes: 0

Jatin Mehrotra
Jatin Mehrotra

Reputation: 11574

When Amazon SNS evaluates message attributes against the subscription filter policy, it ignores message attributes that aren't specified in the policy.

I think in the above statement the understanding of ignore is misleading; treat ignore as "rejected".

Check out this link which shows when the policy rejects messages

If any single attribute in this policy doesn't match an attribute assigned to the message, the policy rejects the message.

On the similar grounds, your filtering policy doesn't have request_id, which is why it is being rejected.

Upvotes: 3

Related Questions