A developer is building a document conversion system that uses an Amazon SQS standard queue to trigger an AWS Lambda function. The Lambda function processes documents in batches of . During testing, the developer observes that if a single document in a batch fails to process due to a timeout, all documents in that batch are retried, causing duplicate processing for the successfully completed documents. Which configuration change should the developer make to ensure only the failed documents are reprocessed?
- ADecrease the SQS queue's visibility timeout to be lower than the Lambda function's timeout so that messages are returned to the queue faster.
- BStore the IDs of successfully processed documents in a global variable in the Lambda function's execution context to prevent them from being reprocessed when the function is reused.
- Configure the event source mapping with ReportBatchItemFailures in the FunctionResponseTypes, and update the Lambda function to return the IDs of the failed messages in the response payload.Cevap
- DInitialize the Amazon SQS client within the Lambda function handler using hardcoded long-term AWS credentials of a user with SQS permissions, and manually delete each message as it finishes processing.
Cevap
Configure the event source mapping with ReportBatchItemFailures in the FunctionResponseTypes, and update the Lambda function to return the IDs of the failed messages in the response payload.
By enabling ReportBatchItemFailures in the FunctionResponseTypes of the Lambda event source mapping, the Lambda service understands when only a subset of messages in a batch fails. The function returns a JSON payload containing the identifiers of the failed messages, allowing SQS to make only those specific messages visible again in the queue while successfully processed messages are deleted from the queue automatically.
Adım Adım Çözüm
Anahtar Kavram
Handling partial batch failures in SQS-Lambda event source mappings using ReportBatchItemFailures