An application publishes event messages to an Amazon SNS topic. An Amazon SQS queue named ShippingQueue is subscribed to this topic, and an AWS Lambda function is configured to process messages from this queue. The developer needs to ensure that the ShippingQueue only receives messages where the message attribute shipping_type is set to physical. Additionally, the developer must prevent messages from being processed by multiple concurrent Lambda instances while the function is actively executing. Which TWO configurations should the developer implement?
- Define a subscription filter policy on the Amazon SNS subscription for the ShippingQueue that checks the shipping_type attribute.Answer
- Configure the visibility timeout of the ShippingQueue to be greater than or equal to the timeout of the consumer Lambda function.Answer
- CConfigure the visibility timeout of the ShippingQueue to be shorter than the Lambda function timeout to ensure failed messages are immediately retried.
- DInitialize the SQS client inside the Lambda function handler using hardcoded IAM access keys and secret keys.
- EConfigure the Lambda function to delete messages from the ShippingQueue at the start of the execution to prevent execution context reuse issues.
Answer
To configure this architecture correctly, the developer must define an SNS subscription filter policy to filter out non-physical orders and set the SQS visibility timeout to be at least the duration of the Lambda function's timeout.
Configuring an SNS subscription filter policy restricts message delivery to only matching messages. Aligning the SQS visibility timeout with the Lambda timeout prevents SQS from releasing the message back into the queue while processing is active.
Step-by-Step Solution
Key Concept
Decoupled architectures using SNS subscription filters restrict message delivery to relevant queues, while SQS visibility timeouts ensure single-consumer processing safety during execution.