Question #1051
A developer is designing a system where messages sent to an Amazon SQS queue must be processed by an AWS Lambda function after a specific delay. The solution should be operationally efficient and minimize custom code.
Which approach meets these requirements?
Use an AWS Step Functions state machine with a Wait state to introduce the delay. Configure an Amazon EventBridge rule to trigger the state machine each time a message arrives in the queue.
Configure the Lambda function to poll the queue and, upon receiving a message, store it in an Amazon DynamoDB table with a Time to Live (TTL) attribute set to the delay duration. Use DynamoDB Streams to trigger the Lambda function when the TTL expires.
Set the DelaySeconds parameter on the SQS queue to the required delay. Create an event source mapping between the SQS queue and the Lambda function.
Set the Visibility Timeout of the SQS queue to the desired delay period. Configure the Lambda function with an event source mapping to the queue, and have the Lambda function delete the message only after the delay has passed.
Explanation
Answer C is correct because:
- DelaySeconds Parameter: SQS natively supports delaying message visibility via DelaySeconds, ensuring messages are processed after the specified delay without additional code.
- Event Source Mapping: Directly linking SQS to Lambda via event source mapping allows Lambda to poll and process messages automatically after the delay, minimizing operational complexity.
Why other options are incorrect:
- A: Step Functions with Wait state introduces unnecessary orchestration complexity and cost, especially for high message volumes. EventBridge cannot directly trigger from SQS without custom polling logic.
- B: DynamoDB TTL is not precise (up to 48-hour delay) and adds extra components (DynamoDB table, streams), requiring custom code to store/retrieve messages.
- D: Visibility Timeout hides messages temporarily but does not delay initial processing. Lambda would need to implement waiting logic, increasing cost and code complexity.
Key Points: Use SQS-native features (DelaySeconds) for delays and event source mappings for serverless integration with Lambda to minimize custom code and maximize efficiency.
Answer
The correct answer is: C