How do I troubleshoot subscription filter policy issues in Amazon SNS?

3 minute read
0

My Amazon Simple Notification Service (Amazon SNS) subscription filter policy doesn't work.

Resolution

Important: Additions or changes to a subscription filter policy require up to 15 minutes to take effect.

A subscription accepts a message only under the following conditions:

  • When you set the filter policy scope to MessageAttributes, each property name in the filter policy matches a message attribute name. For each matching property name in the filter policy, at least one property value matches the message attribute value.
  • When you set the filter policy scope to MessageBody, each property name in the filter policy matches a message body property name. For each matching property name in the filter policy, at least one property value matches the message body property value

Check if your filter policy rejected messages because they didn't include attributes. For attribute based message filtering, review the NumberOfNotificationsFilteredOut-NoMessageAttributes metric in Amazon CloudWatch metrics for Amazon SNS.

For more information, see Amazon SNS message filtering.

For a tutorial on how to send messages with attributes, see To publish messages to Amazon SNS topics using the AWS Management Console.

For a tutorial on how to send messages with payload based filtering, see Publishing with platform-specific payload

Verify that the messages published to your Amazon SNS topic meet the required filter policy constraints

For a complete list of restraints, see Filter policy constraints.

Verify that your subscription filter policy is configured correctly based on Attribute based filtering or Payload based Filtering

If the message includes the MessageAttributes field, then any topic subscription that sets a FilterPolicy can selectively accept or reject the message. To do this, you must also set FilterPolicyScope to MessageAttributes in the subscription.

Similarly, any topic subscription that includes a FilterPolicy can selectively accept or reject the message when you set FilterPolicyScope to MessageBody in the subscription.

For more information on the right filter policy formats, see the following documentation:

To see the messages that your filter policy rejected because of mismatching or incorrectly formatted attributes, review the following CloudWatch metrics for Amazon SNS:

  • NumberOfNotificationsFilteredOut
  • NumberOfNotificationsFilteredOut-InvalidAttributes
  • NumberOfNotificationsFilteredOut-InvalidMessageBody
  • NumberOfNotificationsFilteredOut-MessageBody

Note:

  • The NumberOfNotificationsFilteredOut metric shows messages that your filter policy rejected because the message attributes didn't match the policy attributes.
  • The NumberOfNotificationsFilteredOut-InvalidAttributes metric shows messages that your filter policy rejected because the message attributes weren't in a valid format.
  • The NumberOfNotificationsFilteredOut-MessageBody metric determines the number of messages that were rejected by subscription filter policies for payload-based filtering.
  • The NumberOfNotificationsFilteredOut-InvalidMessageBody is the number of messages that were rejected by subscription filter policies because the message body is not valid for filtering. For example, they were rejected because of a JSON message body that wasn't valid.
AWS OFFICIAL
AWS OFFICIALUpdated 7 months ago
3 Comments

Thank you for your comment. We'll review and update the Knowledge Center article as needed.

profile pictureAWS
MODERATOR
replied a year ago

Hi, The KB still mention that :

Subscription filter policies can filter message attributes only, not the message body.

While it's not the case anymore as pointed out by @rePost-User-1675354.

eric_g
replied 7 months ago