Question

Difficulty: MediumServerless Development with AWS Lambda

A developer is configuring an Amazon SQS event source mapping for an AWS Lambda function that processes customer feedback messages. The SQS queue visibility timeout is configured to 3030 seconds. To optimize message processing, the developer wants to process messages in batches of up to 1010, handle partial batch failures gracefully so that only failed messages are retried, and prevent message processing from timing out before the visibility window expires. Which combination of configurations will achieve these goals? (Select two.)

  1. Configure the Lambda function's timeout to 55 seconds, ensuring the SQS queue visibility timeout is at least 66 times the function's timeout.Answer
  2. Configure the event source mapping to include ReportBatchItemFailures in the function response types, and return a list of failed message IDs in the response payload.Answer
  3. C
    Configure the Lambda function's timeout to 3030 seconds to match the SQS queue's visibility timeout exactly.
  4. D
    Return an HTTP 500500 Internal Server Error status code from the Lambda function handler to signal SQS to retry only the failed messages.
  5. E
    Configure the Lambda function to delete successfully processed messages from the SQS queue using the AWS SDK within the function code.

Answer

Configure the Lambda function's timeout to 55 seconds, ensuring the SQS queue visibility timeout is at least 66 times the function's timeout, and configure the event source mapping to include ReportBatchItemFailures in the function response types, and return a list of failed message IDs in the response payload.
To handle partial batch failures in Amazon SQS event source mappings without reprocessing successful messages, developers should enable ReportBatchItemFailures in the FunctionResponseTypes of the event source mapping. The Lambda function must then return a JSON response containing a batchItemFailures list with the identifiers of the failed messages. Additionally, to prevent message processing from timing out and causing duplicate delivery before SQS visibility expires, the visibility timeout of the SQS queue must be configured to at least 66 times the Lambda function's timeout. Since the SQS queue's visibility timeout is 3030 seconds, the Lambda function's timeout should be configured to 55 seconds or less.

Step-by-Step Solution

1
Analyze the relationship between SQS visibility timeout and Lambda function timeout.
Determine that the SQS visibility timeout must be at least 66 times the Lambda timeout (306×Lambda Timeout30 \ge 6 \times \text{Lambda Timeout}).
To prevent duplicate processing caused by the SQS visibility window expiring while the Lambda function is still running.
2
Calculate the maximum allowed Lambda function timeout.
The Lambda function timeout should be configured to 55 seconds or less (30/6=530 / 6 = 5).
Ensures the Lambda function's timeout satisfies the 66 times visibility timeout requirement.
3
Configure partial batch processing for the SQS event source mapping.
Enable ReportBatchItemFailures in the event source mapping and structure the Lambda function to return failed message IDs in a batchItemFailures list.
Allows SQS to delete successful messages automatically and only retry failed messages from the batch.

Key Concept

Integrating AWS Lambda with Amazon SQS involves configuring the function timeout relative to SQS visibility timeout to prevent duplicate processing, and utilizing ReportBatchItemFailures to handle partial batch processing errors efficiently.
Rate this question