Question

Difficulty: MediumMessage-Based Integration using Amazon SQS and SNS

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?

  1. 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
  2. Increase the execution timeout of the Lambda function to 7 minutes (420 seconds) to allow the transcoding process to complete.Answer
  3. C
    Decrease the SQS queue's visibility timeout to 1 minute to allow other consumers to process failed messages faster.
  4. D
    Decrease the Lambda function's execution timeout to 2 seconds to force rapid execution context recycling.
  5. E
    Hardcode 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

1
Analyze the execution duration of the backend processing task.
The transcoding task takes approximately 6 minutes, which exceeds the default Lambda timeout and standard SQS visibility window.
Identifying the processing duration helps establish the minimum required thresholds for Lambda execution limits and queue visibility configurations.
2
Adjust the Lambda function's execution timeout to accommodate the workload.
The execution timeout is configured to 7 minutes (420 seconds).
This prevents the Lambda function from being aborted by AWS while the 6-minute transcoding task is running.
3
Apply AWS best practices to configure the SQS queue's visibility timeout based on the new Lambda timeout.
The SQS queue's visibility timeout is set to 42 minutes (6 times the Lambda timeout).
A visibility timeout of at least six times the function's timeout prevents messages from returning to the queue and being reprocessed by another instance before the active Lambda function has finished processing them.

Key Concept

Configuring SQS visibility timeout in relation to Lambda function timeouts to prevent duplicate message processing.
Rate this question