By default, an Amazon SNS topic subscriber receives every message published to the topic. To receive a subset of the messages, a subscriber must assign a filter policy to the topic subscription. A filter policy is a simple JSON object containing attributes that define which messages the subscriber receives.
When you publish a message to a topic, Amazon SNS compares the message attributes to the attributes in the filter policy for each of the topic’s subscriptions. If any of the attributes match, Amazon SNS sends the message to the subscriber. Otherwise, Amazon SNS skips the subscriber without sending the message.
You can simplify your use of Amazon SNS by consolidating your message filtering criteria into your topic subscriptions. This allows you to offload the message filtering logic from subscribers and the message routing logic from publishers, eliminating the need to filter messages by creating a separate topic for each condition. You can use a single topic, differentiating your messages using attributes. Each subscriber receives and processes only the messages accepted by its filter policy.
In this section, you will create a new SQS queue for EU Orders, and create a subscription to the Orders SNS topic with a filter policy to route each message to the EU Orders SQS queue. To indicate EU Orders, you will assign an attribute, location, with a value eu-west to the message.
Access to SQS
In the Create queue interface
Orders-EU
In the Orders interface find Orders-EU SQS queue subscription.
{
"location": [
"eu-west"
]
}
Use Event Generator to test push messages.
In the Event Generator interface
category
books
In the Event Generator interface
attribute Type
, select Stringlocation
us-west
In the Event Generator interface
attribute Type
, select Stringlocation
eu-west
In this step we will generate a message with attributes and values that match the filter policy we have set.
Confirm push message successfully.