Question #1029
A developer is troubleshooting an AWS Lambda function triggered by an Amazon Simple Queue Service (Amazon SQS) queue. The Lambda function processes messages in batches, but some messages are becoming visible in the queue again before processing completes, leading to duplicate processing.
The developer needs to ensure messages remain hidden until processing finishes.
Which solution will resolve this issue?
Increase the maximum execution timeout of the Lambda function.
Increase the visibility timeout of the SQS queue.
Increase the ephemeral storage size of the Lambda function.
Increase the retry attempts in the event source mapping.
Explanation
The issue arises because the SQS queue's visibility timeout is shorter than the time the Lambda function takes to process messages. When a message is polled, it becomes temporarily invisible. If processing exceeds this timeout, the message reappears, causing duplicates.
- Option B resolves this by increasing the visibility timeout to match the processing duration, ensuring messages stay hidden.
- Option A (Lambda timeout) controls execution time but doesn't affect SQS message visibility.
- Option C (ephemeral storage) addresses storage constraints, not visibility.
- Option D (retry attempts) relates to handling failures, not processing time.
Key Points: SQS visibility timeout must exceed the Lambda processing time to avoid duplicates. Adjusting this timeout aligns message invisibility with the function's runtime.
Answer
The correct answer is: B