A developer is implementing a serverless worker using an AWS Lambda function triggered by an Amazon SQS queue. During performance testing, the developer observes that messages are frequently being processed multiple times by parallel Lambda executions. The Lambda function has an execution timeout of seconds, whereas the SQS queue has a visibility timeout of seconds. Which modification will prevent the messages from being processed multiple times?
- Increase the SQS queue visibility timeout to at least seconds.Answer
- BIncrease the AWS Lambda execution timeout to seconds.
- CHardcode administrative AWS IAM credentials in the Lambda function's initialization code.
- DAssociate the AWS Lambda function with a custom VPC and deploy it across private subnets without a NAT Gateway.
Answer
Increase the SQS queue visibility timeout to at least seconds.
Increasing the SQS queue visibility timeout to at least seconds is correct because AWS recommends setting the visibility timeout of the source SQS queue to at least times the execution timeout of the target Lambda function. This prevents messages from becoming visible again to other consumers while a Lambda function is still actively processing them.
Step-by-Step Solution
Key Concept
SQS visibility timeout vs Lambda timeout configuration