Question

Difficulty: MediumDebugging Lambda Execution and Configuration Issues

A developer is troubleshooting a serverless application where an Amazon SQS queue triggers an AWS Lambda function to process batch invoice reports. Under normal load, the invoices are processed successfully. However, during peak hours when processing times increase, the developer notices that some invoices are generated multiple times. CloudWatch logs show that the Lambda function occasionally runs for up to 4545 seconds before completion, which is close to its configured timeout. The SQS queue's visibility timeout is currently set to 3030 seconds. Which configuration change will resolve this duplicate processing issue?

  1. Increase the SQS queue's visibility timeout to at least 270270 seconds.Answer
  2. B
    Reduce the Lambda function's execution timeout to 2525 seconds.
  3. C
    Configure a Dead-Letter Queue (DLQ) on the SQS queue with a maxReceiveCount of 11.
  4. D
    Increase the SQS queue's visibility timeout to 5050 seconds.

Answer

Increase the SQS queue's visibility timeout to at least 270270 seconds.
The correct option addresses the timeout mismatch by setting the SQS visibility timeout to 270270 seconds, which satisfies the AWS best practice of maintaining the queue's visibility timeout at least 66 times the Lambda function's timeout. This prevents SQS from delivering the same message to another Lambda execution thread while the active thread is still processing the invoice.

Step-by-Step Solution

1
Identify the relationship between the Lambda function's timeout and the SQS queue's visibility timeout.
The Lambda function timeout is 4545 seconds, but the SQS visibility timeout is only 3030 seconds.
When the visibility timeout is shorter than the Lambda execution time, SQS makes the message visible to other consumers while the current Lambda execution is still running, causing duplicate processing.
2
Apply the AWS recommended formula for SQS-to-Lambda integration timeouts.
Visibility Timeout 6×\geq 6 \times Lambda Timeout.
The safety margin of 66 times the function timeout allows Lambda to retry the function if it is throttled or returns an error while processing a previous batch.
3
Calculate the minimum visibility timeout required.
6×45 seconds=270 seconds6 \times 45\text{ seconds} = 270\text{ seconds}.
This is the minimum duration the visibility timeout should be set to prevent duplicate processing during peak hours.

Key Concept

SQS visibility timeout configuration when integrated with Lambda
Rate this question