A developer is implementing a serverless video processing pipeline. When a user uploads a new video, an Amazon SNS topic publishes an event that is fanned out to an Amazon SQS queue. An AWS Lambda function is configured to process messages from this SQS queue and perform CPU-intensive transcoding, which takes approximately 6 minutes per video. During initial testing, the developer notices two issues: some videos are processed multiple times, resulting in duplicate files in the target Amazon S3 bucket, and the Lambda function periodically times out before completing the transcoding task. Which two configuration changes should the developer implement to resolve these issues?
- Increase the visibility timeout of the SQS queue to 42 minutes, following the AWS best practice of setting it to at least six times the Lambda function's timeout.Answer
- Increase the execution timeout of the Lambda function to 7 minutes (420 seconds) to allow the transcoding process to complete.Answer
- CDecrease the SQS queue's visibility timeout to 1 minute to allow other consumers to process failed messages faster.
- DDecrease the Lambda function's execution timeout to 2 seconds to force rapid execution context recycling.
- EHardcode AWS access keys in the Lambda function code to bypass IAM role lookup latency during S3 uploads.
Answer
Increase the visibility timeout of the SQS queue to 42 minutes, and increase the execution timeout of the Lambda function to 7 minutes (420 seconds).
To ensure messages are processed successfully exactly once without duplicate processing, the developer must align the Lambda function execution timeout and the SQS visibility timeout. First, the Lambda execution timeout must be increased to at least 7 minutes so that the 6-minute transcoding task can finish without being killed. Second, the SQS visibility timeout must be increased to at least 42 minutes (six times the Lambda function timeout). This prevents SQS from making the message visible to other consumers while the Lambda function is actively processing it, avoiding duplicate deliveries.
Step-by-Step Solution
Key Concept
Configuring SQS visibility timeout in relation to Lambda function timeouts to prevent duplicate message processing.