How do I troubleshoot Lambda function SQS ReportBatchItemFailures?
"I set up Partial Batch Response for my AWS Lambda function that has Amazon Simple Queue Service (Amazon SQS) configured as an event source. Now, my Lambda function is returning a list of "ReportBatchItemFailures" and one of the following occurs: Lambda retries an entire message batch when there wasn't a function error, or Lambda doesn't retry any of the partial message batches. How do I troubleshoot the issue?"
"I set up Partial Batch Response for my AWS Lambda function that has Amazon Simple Queue Service (Amazon SQS) configured as an event source. Now, my Lambda function is returning a list of "ReportBatchItemFailures" and one of the following occurs: Lambda retries an entire message batch when there wasn't a function error, or Lambda doesn't retry any of the partial message batches. How do I troubleshoot the issue?ResolutionNote: You must manually configure Partial Batch Response on your Lambda function to programmatically process partial Amazon SQS batches. For more information, see Reporting batch item failures in the AWS Lambda Developer Guide.Example AWS Command Line Interface (AWS CLI) command to activate Partial Batch Response for a Lambda functionImportant: Replace <esm_UUID> with your Amazon SQS event source mapping's universally unique identifier (UUID). To retrieve your event source mapping's UUID, run the list-event-source-mappings AWS CLI command. If you receive errors when running AWS CLI commands, make sure that you're using the most recent version of the AWS CLI.aws lambda update-event-source-mapping --uuid <esm_UUID> --function-response-types "ReportBatchItemFailures"To troubleshoot ReportBatchItemFailures where Lambda retries an entire SQS message batch when there wasn't a function errorReview the Partial Batch Response in your Lambda function's code to see if there are any of the following responses. Then, remediate the issue based on the response that's recorded.Note: Lambda treats a batch as a complete failure if your function returns any of the following responses.Responses for an EventResponse that isn't valid JSONreturn "Hello world"return ""Response for an empty itemIdentifier valuereturn {"batchItemFailures":[{"itemIdentifier": ""}]}Response for a null itemIdentifier valuereturn {"batchItemFailures":[{"itemIdentifier": None}]}Response for an itemIdentifier value with an incorrect key namereturn {"batchItemFailures":[{"bad_key": messageID}]}Response for an itemIdentifier value with a message ID that doesn't existreturn {"batchItemFailures":[{"itemIdentifier": "random_ID"}]}Important: Your Lambda function must return a valid itemIdentifier JSON value.To troubleshoot ReportBatchItemFailures where Lambda doesn't retry any of the partial message batchesReview the Partial Batch Response in your Lambda function's code to see if there are any of the following responses. Then, remediate the issue based on the response that's recorded.Note: Lambda treats a batch as a complete success when your function returns any of the following responses.Response for an empty batchItemFailures listreturn {"batchItemFailures":[]}Response for a null batchItemFailures listreturn {"batchItemFailures": None}Responses for an EventResponse with an empty or unexpected JSON valuereturn {}return {"Key1":"Value1"}Responses for a null EventResponsereturnreturn NoneImportant: Your Lambda function must return a response that contains a "batchItemFailures" JSON value that includes a list of valid message IDs.Related informationHow can I prevent an Amazon SQS message from invoking my Lambda function more than once?Follow"