Introduction
Lambda processes Kinesis/DynamoDB streams in batches. With the BatchItemProcessor, failed items can be handled individually without failing the entire batch. When the processor fails, all items in the batch get retried, including successful ones, causing duplicate processing and backpressure on the stream.
Symptoms
Batch processing failures:
```bash $ aws logs filter-log-events --log-group-name /aws/lambda/my-stream-processor
"errorType": "BatchItemFailure", "errorMessage": "Item with sequence number 12345 failed processing" ```
Iterator age increasing:
```bash $ aws cloudwatch get-metric-statistics \ --namespace AWS/Lambda \ --metric-name IteratorAge \ --dimensions Name=FunctionName,Value=my-stream-processor
# Iterator age increasing = processing blocked # High age means falling behind stream ```
Partial batch response errors:
```bash $ aws logs filter-log-events --log-group-name /aws/lambda/my-stream-processor
"errorType": "InvalidPartialBatchResponse", "errorMessage": "batchItemFailures must be array of sequence numbers" ```
Common Causes
- 1.Partial batch response malformed - Incorrect response format
- 2.Sequence number format wrong - Must match stream format
- 3.All items failing - No partial success possible
- 4.Batch size too large - Timeout before processing complete
- 5.Processing errors unhandled - Exceptions not caught
- 6.Checkpoint logic wrong - Wrong sequence numbers reported
- 7.Stream throttling - Lambda can't keep up with stream rate
Step-by-Step Fix
- 1.Check logs for specific error messages
- 2.Verify configuration settings
- 3.Test network connectivity
- 4.Review recent changes
- 5.Apply corrective action
- 6.Verify the fix
Step 1: Check Current Batch Configuration
```bash # Get event source mapping aws lambda get-event-source-mapping \ --uuid "uuid-from-list-event-source-mappings" \ --query '{BatchSize:BatchSize,MaximumBatchingWindow:MaximumBatchingWindowInSeconds,FunctionResponseConfig:FunctionResponseTypes}'
# Check if ReportBatchItemFailures enabled # FunctionResponseTypes should include "ReportBatchItemFailures" ```
Step 2: Enable Partial Batch Failure Reporting
```bash # Update event source mapping to support partial batch failures aws lambda update-event-source-mapping \ --uuid "mapping-uuid" \ --function-response-types '["ReportBatchItemFailures"]'
# This allows Lambda to report which items failed # Failed items are retried, successful items are checkpointed ```
Step 3: Implement Correct Response Format
For Kinesis streams:
```python # Lambda function must return this format for partial failures: def lambda_handler(event, context): batch_item_failures = []
for record in event['Records']: try: # Process record process_record(record) except Exception as e: # Record sequence number for retry batch_item_failures.append({ 'itemIdentifier': record['kinesis']['sequenceNumber'] })
return { 'batchItemFailures': batch_item_failures } ```
For DynamoDB streams:
```python def lambda_handler(event, context): batch_item_failures = []
for record in event['Records']: try: process_record(record) except Exception as e: batch_item_failures.append({ 'itemIdentifier': record['dynamodb']['SequenceNumber'] })
return { 'batchItemFailures': batch_item_failures } ```
Step 4: Verify Sequence Number Format
```bash # Check sequence numbers in your stream aws kinesis get-records --stream-arn arn:aws:kinesis:us-west-2:123456789:stream/my-stream
# Kinesis sequence number format: string, e.g., "496293496293496293496293" # DynamoDB: similar long numeric string
# Ensure Lambda returns exact sequence numbers from records # No modification or truncation ```
Step 5: Reduce Batch Size
```bash # Reduce batch size if processing times out aws lambda update-event-source-mapping \ --uuid "mapping-uuid" \ --batch-size 10 # Default is 100 for Kinesis
# Smaller batches mean less work per invocation # Faster checkpointing for successful items ```
Step 6: Increase Parallel Batch Factor
```bash # For high-throughput streams, increase parallel batches aws lambda update-event-source-mapping \ --uuid "mapping-uuid" \ --parallelization-factor 10 # Process 10 batches concurrently
# Default is 1 # Higher factor processes more shards simultaneously ```
Step 7: Check Iterator Age
```bash # Monitor iterator age aws cloudwatch get-metric-statistics \ --namespace AWS/Lambda \ --metric-name IteratorAge \ --dimensions Name=FunctionName,Value=my-stream-processor \ --statistics Maximum \ --period 60
# High iterator age (> 10000ms) = processing falling behind # If consistently high, increase Lambda resources ```
Step 8: Handle Specific Processing Errors
```python # Implement robust error handling def lambda_handler(event, context): failures = []
for record in event['Records']: sequence = get_sequence_number(record)
try: data = decode_record(record) validate_data(data) process_data(data)
except ValidationError as e: # Invalid data - don't retry, mark as success # to skip this record permanently logger.error(f"Invalid data, skipping: {sequence}")
except TransientError as e: # Temporary error - retry this record failures.append({'itemIdentifier': sequence})
except Exception as e: # Unknown error - retry failures.append({'itemIdentifier': sequence}) logger.error(f"Processing error: {e}")
return {'batchItemFailures': failures} ```
Step 9: Configure Retry Policy
```bash # Check retry configuration aws lambda get-event-source-mapping \ --uuid "mapping-uuid" \ --query '{MaximumRetryAttempts:MaximumRetryAttempts,MaximumRecordAge:MaximumRecordAgeInSeconds}'
# After max retries, failed records go to: # - OnFailure destination (if configured) # - DLQ (older configuration)
# Adjust retry attempts aws lambda update-event-source-mapping \ --uuid "mapping-uuid" \ --maximum-retry-attempts 5 ```
Step 10: Check for Throttling
```bash # Check Lambda throttling aws cloudwatch get-metric-statistics \ --namespace AWS/Lambda \ --metric-name Throttles \ --dimensions Name=FunctionName,Value=my-stream-processor
# If throttled, increase concurrent executions limit # Or reserved concurrency for this function
aws lambda put-function-concurrency \ --function-name my-stream-processor \ --reserved-concurrent-executions 100 ```
Batch Processing Metrics Reference
| Metric | Normal | Warning | Critical |
|---|---|---|---|
| IteratorAge | < 1000ms | 1000-10000ms | > 10000ms |
| BatchSuccessRate | > 95% | 80-95% | < 80% |
| ProcessingLatency | < 100ms/item | 100-500ms | > 500ms |
Verification
```bash # Test with sample records aws kinesis put-record \ --stream-name my-stream \ --data "test-data" \ --partition-key "test"
# Monitor Lambda logs aws logs tail /aws/lambda/my-stream-processor --follow
# Check iterator age decreased aws cloudwatch get-metric-statistics \ --namespace AWS/Lambda \ --metric-name IteratorAge \ --dimensions Name=FunctionName,Value=my-stream-processor \ --statistics Maximum ```
Related Issues
- [Fix AWS Lambda Kinesis Trigger Not Working](/articles/fix-aws-lambda-kinesis-trigger-not-working)
- [Fix AWS Lambda Function Timeout](/articles/fix-aws-lambda-function-timeout)
- [Fix AWS Kinesis Stream Throttling](/articles/fix-aws-kinesis-stream-throttling)
Related Articles
- [AWS troubleshooting: Fix IAM Permission Denied - Complete Tro](fix-iam-permission-denied)
- [AWS cloud troubleshooting: AWS ACM Certificate Pending Validation Because the](aws-acm-certificate-pending-validation-wrong-route53-zone)
- [AWS cloud troubleshooting: AWS ALB Returns 502 Because the Target Closed the ](aws-alb-502-target-closed-connection-keepalive-timeout-mismatch)
- [AWS cloud troubleshooting: Fix AWS ALB CreateListener TargetGroupNotFound Err](aws-alb-createlistener-targetgroupnotfound)
- [AWS cloud troubleshooting: Fix Aws Alb Lambda 502 Bad Gateway Issue in AWS](aws-alb-lambda-502-bad-gateway)
<script type="application/ld+json"> { "@context": "https://schema.org", "@type": "TechArticle", "headline": "Fix AWS Lambda Stream Batch Item Processor Failed", "description": "Troubleshoot Lambda stream batch processing failures. Configure partial batch responses and error handling.", "url": "https://www.fixwikihub.com/fix-aws-lambda-stream-batchitem-processor-failed", "publisher": { "@type": "Organization", "name": "FixWikiHub", "url": "https://www.fixwikihub.com" }, "author": { "@type": "Person", "name": "FixWikiHub Editorial Team" }, "datePublished": "2026-04-02T05:29:01.760Z", "dateModified": "2026-04-02T05:29:01.760Z" } </script>