Controlling Notifications with AWS Simple Notification Service - DVA-C01 Exam Prep

Controlling Notifications with AWS Simple Notification Service

Prev Question Next Question

Question

A company uses the Simple Notification Service to send notifications to various subscribers for their service.

There is a user requirement for the subscriber only to receive certain types of messages and not all messages published to the topic.

How can you achieve this?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

Answer - A.

The AWS Documentation mentions the following.

By default, a subscriber of an Amazon SNS topic receives every message published to the topic.

A subscriber assigns a filter policy to the topic subscription to receive only a subset of the messages.

A filter policy is a simple JSON object.

The policy contains 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 there is a match between the attributes, Amazon SNS sends the message to the subscriber.

Otherwise, Amazon SNS skips the subscriber without sending the message to it.

If a subscription lacks a filter policy, the subscription receives every message published to its topic.

Since the documentation clearly mentions this, all other options are incorrect.

For more information on message filtering, please refer to the below URL-

https://docs.aws.amazon.com/sns/latest/dg/message-filtering.html

The correct answer is A. By adding a filter policy to the topic subscription.

The Simple Notification Service (SNS) is a fully managed messaging service that enables the publishing and delivery of messages to multiple subscribers or endpoints. It allows messages to be sent as text messages, emails, or to other AWS services such as Lambda functions or SQS queues.

When a topic has multiple subscribers, each subscriber receives a copy of every message published to the topic by default. However, if you want certain subscribers to receive only specific types of messages, you can add a filter policy to the subscription.

A filter policy is a JSON document that specifies the attributes and values of the messages that a subscriber is interested in receiving. You can use filter policies to select a subset of messages that match certain criteria. When a message is published to the topic, SNS evaluates the message attributes against the filter policy of each subscription. If the message attributes match the filter policy of a subscription, SNS sends the message to that subscription.

Here is an example of a filter policy:

json
{ "type": ["order_placed", "order_shipped"], "price": [{"numeric": [">=", 50]}, {"numeric": [">=", 100], "anything-but": true}] }

In this example, the filter policy selects messages with a type attribute that is either order_placed or order_shipped, and a price attribute that is either greater than or equal to 50 or greater than or equal to 100 (but not both). The anything-but operator negates the condition.

To add a filter policy to a topic subscription, follow these steps:

  1. Open the Amazon SNS console.
  2. In the left navigation pane, choose "Subscriptions".
  3. Select the subscription that you want to modify.
  4. Choose "Edit subscription".
  5. In the "Filter policy" field, enter the filter policy as a JSON document.
  6. Choose "Update subscription".

In summary, by adding a filter policy to a topic subscription, you can specify the types of messages that a subscriber is interested in receiving and filter out unwanted messages. This is a powerful feature of SNS that allows you to customize the delivery of messages to your subscribers.