Question

Difficulty: MediumMessage-Based Integration using Amazon SQS and SNS

A developer is configuring an AWS Lambda function to process messages from an Amazon SQS standard queue. The Lambda function has a timeout of 20 seconds. The SQS queue has a default visibility timeout of 20 seconds. During testing, the developer observes that some messages are processed more than once by different Lambda executions. Which configuration change should the developer make to resolve this issue?

  1. Increase the default visibility timeout of the SQS queue to 120 seconds.Answer
  2. B
    Increase the Lambda function timeout to 120 seconds.
  3. C
    Decrease the default visibility timeout of the SQS queue to 5 seconds.
  4. D
    Initialize the SQS client inside the Lambda function handler and hardcode temporary credentials to delete messages before processing.

Answer

Increase the default visibility timeout of the SQS queue to 120 seconds.
Increasing the SQS visibility timeout to 120 seconds (which is 6 times the Lambda function's timeout of 20 seconds) ensures that a message remains invisible to other consumers long enough for the Lambda function to finish processing, retry if necessary, and delete the message from the queue.

Step-by-Step Solution

1
Identify the current configuration of the Lambda function and the SQS queue.
Lambda timeout is 20 seconds, and SQS visibility timeout is 20 seconds.
To determine the relationship between function execution duration and message visibility.
2
Apply AWS best practices for SQS queue visibility timeout when integrated with Lambda.
The SQS visibility timeout should be set to at least 6 times the Lambda function timeout.
This recommendation prevents duplicate message processing by ensuring that if a batch fails or is retried, the message does not become visible to other instances too quickly.
3
Calculate the recommended visibility timeout and update the queue configuration.
20 seconds multiplied by 6 equals 120 seconds.
To set the queue's default visibility timeout to 120 seconds.

Key Concept

Integrating Amazon SQS with AWS Lambda requires setting the queue's visibility timeout to at least 6 times the Lambda function's timeout to prevent duplicate processing.
Estimated Time:1m 30s
Rate this question