A developer is implementing a serverless integration where an Amazon Simple Queue Service (Amazon SQS) queue triggers an AWS Lambda function to process batch data. Each batch of messages takes approximately 4 minutes to process, and the Lambda function's timeout is configured to 5 minutes. During testing, the developer notices that many messages are being received and processed multiple times by separate Lambda execution environments. Which action should the developer take to prevent these duplicate executions?
- AConfigure the SQS queue's visibility timeout to 3 minutes to match the average batch processing time.
- Increase the Amazon SQS queue's visibility timeout to at least 30 minutes.Cevap
- CIncrease the AWS Lambda function's timeout to 30 minutes to allow ample time for all retries.
- DUpdate the AWS Lambda function's IAM execution role trust policy to grant the sqs:DeleteMessage permission.
Cevap
Increase the Amazon SQS queue's visibility timeout to at least 30 minutes.
To prevent duplicate processing of SQS messages by Lambda, the SQS queue's visibility timeout must be set to at least 6 times the Lambda function's timeout. Since the Lambda function timeout is 5 minutes, the visibility timeout must be configured to at least 30 minutes (). This ensures messages remain invisible while the Lambda function processes the batch and handles any potential retries.
Adım Adım Çözüm
Anahtar Kavram
Amazon SQS visibility timeout configuration for AWS Lambda integrations