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?
- ADecrease the visibility timeout of the SQS queue for the shipping service below the average message processing time to reject unwanted messages.
- BDeploy a Lambda consumer to inspect the events, using a shared global array in the execution context to track and filter states across distinct invocations.
- CConfigure a custom Lambda function to intercept and filter the messages by initializing the AWS SDK client with hardcoded AWS access keys.
- 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
Key Concept
Amazon SNS Subscription Filter Policies
Estimated Time:50s