Bug
When raise_on_entire_batch_failure=False and a record handler throws, BatchProcessor.response() can crash with:
in _collect_sqs_failures() via msg.message_id.
This happens if the inbound SQS record is missing messageId (malformed/custom event injection).
Repro
from aws_lambda_powertools.utilities.batch import BatchProcessor, EventType
processor = BatchProcessor(event_type=EventType.SQS, raise_on_entire_batch_failure=False)
def record_handler(record):
raise RuntimeError("boom")
bad_record = {
"body": "{}",
"receiptHandle": "rh",
"attributes": {"ApproximateReceiveCount": "1"},
"messageAttributes": {},
"md5OfBody": "abc",
"eventSource": "aws:sqs",
"eventSourceARN": "arn:aws:sqs:us-east-1:123:q",
"awsRegion": "us-east-1",
}
with processor(records=[bad_record], handler=record_handler):
processor.process()
processor.response() # KeyError: 'messageId'
Expected
Return partial batch response (empty itemIdentifier or explicit error), not crash the Lambda.
Proof after fix
tests/functional/batch/required_dependencies/test_utilities_batch.py::test_sqs_batch_processor_missing_message_id_does_not_crash_on_handler_failure PASSED
PR incoming.
Bug
When
raise_on_entire_batch_failure=Falseand a record handler throws,BatchProcessor.response()can crash with:in
_collect_sqs_failures()viamsg.message_id.This happens if the inbound SQS record is missing
messageId(malformed/custom event injection).Repro
Expected
Return partial batch response (empty
itemIdentifieror explicit error), not crash the Lambda.Proof after fix
PR incoming.