Skip to content

Commit bd0cde8

Browse files
committed
fix: addressed the rest of the comments
1 parent f099c94 commit bd0cde8

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

docs/utilities/batch.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ For these scenarios, you can subclass `BatchProcessor` and quickly override `suc
313313
???+ example
314314
Let's suppose you'd like to add a metric named `BatchRecordFailures` for each batch record that failed processing
315315

316-
```python title="Extending failure handling mechanism in BatchProcessor"
316+
```python hl_lines="8 9 16-19 22 38" title="Extending failure handling mechanism in BatchProcessor"
317317
--8<-- "examples/batch_processing/src/extending_failure.py"
318318
```
319319

@@ -328,7 +328,7 @@ You can create your own partial batch processor from scratch by inheriting the `
328328

329329
You can then use this class as a context manager, or pass it to `batch_processor` to use as a decorator on your Lambda handler function.
330330

331-
```python hl_lines="9 16 31 37 44 55 60 68" title="Creating a custom batch processor"
331+
```python hl_lines="9-12 20 35 41 48 59 64 68 76" title="Creating a custom batch processor"
332332
--8<-- "examples/batch_processing/src/custom_partial_processor.py"
333333
```
334334

examples/batch_processing/src/custom_partial_processor.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@
66
import boto3
77

88
from aws_lambda_powertools import Logger
9-
from aws_lambda_powertools.utilities.batch import BasePartialProcessor, batch_processor
9+
from aws_lambda_powertools.utilities.batch import (
10+
BasePartialBatchProcessor,
11+
EventType,
12+
process_partial_response,
13+
)
1014

1115
table_name = os.getenv("TABLE_NAME", "table_not_found")
1216

1317
logger = Logger()
1418

1519

16-
class MyPartialProcessor(BasePartialProcessor):
20+
class MyPartialProcessor(BasePartialBatchProcessor):
1721
"""
1822
Process a record and stores successful results at a Amazon DynamoDB Table
1923
@@ -26,7 +30,7 @@ class MyPartialProcessor(BasePartialProcessor):
2630
def __init__(self, table_name: str):
2731
self.table_name = table_name
2832

29-
super().__init__()
33+
super().__init__(event_type=EventType.SQS)
3034

3135
def _prepare(self):
3236
# It's called once, *before* processing
@@ -61,10 +65,12 @@ async def _async_process_record(self, record: dict):
6165
raise NotImplementedError()
6266

6367

68+
processor = MyPartialProcessor(table_name)
69+
70+
6471
def record_handler(record):
6572
return randint(0, 100)
6673

6774

68-
@batch_processor(record_handler=record_handler, processor=MyPartialProcessor(table_name))
6975
def lambda_handler(event, context):
70-
return {"statusCode": 200}
76+
return process_partial_response(event=event, record_handler=record_handler, processor=processor, context=context)

examples/batch_processing/src/disable_tracing.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from aws_lambda_powertools.utilities.batch import (
55
BatchProcessor,
66
EventType,
7-
batch_processor,
7+
process_partial_response,
88
)
99
from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord
1010
from aws_lambda_powertools.utilities.typing import LambdaContext
@@ -24,6 +24,5 @@ def record_handler(record: SQSRecord):
2424

2525
@logger.inject_lambda_context
2626
@tracer.capture_lambda_handler
27-
@batch_processor(record_handler=record_handler, processor=processor)
2827
def lambda_handler(event, context: LambdaContext):
29-
return processor.response()
28+
return process_partial_response(event=event, record_handler=record_handler, processor=processor, context=context)

0 commit comments

Comments
 (0)