Question

Difficulty: EasyMessage-Based Integration using Amazon SQS and SNS

A payment service in a microservices application publishes transaction events to an Amazon SNS topic. An invoice service and a shipping service are subscribed to this topic using Amazon SQS queues. The developer needs to ensure that the shipping service only processes messages where the transaction status is marked as 'Success', without modifying the code of the payment service. Which approach should the developer take to meet this requirement?

  1. A
    Decrease the visibility timeout of the SQS queue for the shipping service below the average message processing time to reject unwanted messages.
  2. B
    Deploy a Lambda consumer to inspect the events, using a shared global array in the execution context to track and filter states across distinct invocations.
  3. C
    Configure a custom Lambda function to intercept and filter the messages by initializing the AWS SDK client with hardcoded AWS access keys.
  4. Configure an Amazon SNS subscription filter policy on the subscription for the shipping service queue.Answer

Answer

Configure an Amazon SNS subscription filter policy on the subscription for the shipping service queue.
An Amazon SNS subscription filter policy is the correct mechanism because it enables message filtering natively at the subscription layer. By defining a filter policy on the SQS queue's subscription to the SNS topic, Amazon SNS will only deliver messages that have attributes matching the policy (e.g., status is 'Success'). This completely avoids modifying the payment service (publisher) and does not require deploying additional intermediate resources.

Step-by-Step Solution

1
Analyze the requirement to route messages selectively to a specific SQS queue without modifying the publisher's code.
Identify that the publishing service (payment service) sends all messages to an SNS topic, and the shipping service's queue is subscribed to this topic.
Understanding the current message flow helps determine where to apply the filtering logic.
2
Evaluate the native filtering capabilities of Amazon SNS and SQS.
Amazon SNS supports subscription filter policies, which allow subscribers to receive only a subset of messages based on message attributes.
Applying the filter at the subscription level avoids introducing extra components like Lambda or modifying the publisher code.
3
Configure the filter policy on the subscription representing the SQS queue for the shipping service.
The shipping service queue will only receive events where the status attribute matches 'Success', completing the requirement.
This implements the filter natively, efficiently, and securely.

Key Concept

Amazon SNS Subscription Filter Policies
Estimated Time:50s
Rate this question