@@ -314,34 +314,7 @@ For these scenarios, you can subclass `BatchProcessor` and quickly override `suc
314
314
Let's suppose you'd like to add a metric named ` BatchRecordFailures ` for each batch record that failed processing
315
315
316
316
``` python title="Extending failure handling mechanism in BatchProcessor"
317
-
318
- from typing import Tuple
319
-
320
- from aws_lambda_powertools import Metrics
321
- from aws_lambda_powertools.metrics import MetricUnit
322
- from aws_lambda_powertools.utilities.batch import BatchProcessor, ExceptionInfo, EventType, FailureResponse, process_partial_response
323
- from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord
324
-
325
-
326
- class MyProcessor (BatchProcessor ):
327
- def failure_handler (self , record : SQSRecord, exception : ExceptionInfo) -> FailureResponse:
328
- metrics.add_metric(name = " BatchRecordFailures" , unit = MetricUnit.Count, value = 1 )
329
- return super ().failure_handler(record, exception)
330
-
331
- processor = MyProcessor(event_type = EventType.SQS )
332
- metrics = Metrics(namespace = " test" )
333
-
334
-
335
- @tracer.capture_method
336
- def record_handler (record : SQSRecord):
337
- payload: str = record.body
338
- if payload:
339
- item: dict = json.loads(payload)
340
- ...
341
-
342
- @metrics.log_metrics (capture_cold_start_metric = True )
343
- def lambda_handler (event , context : LambdaContext):
344
- return process_partial_response(event = event, record_handler = record_handler, processor = processor, context = context)
317
+ -- 8 < -- " examples/batch_processing/src/extending_failure.py"
345
318
```
346
319
347
320
### Create your own partial processor
0 commit comments