Skip to content

Commit c999f96

Browse files
committed
refactor: changes partial_sqs middleware in favor of a generic interface always expecting a BatchProcessor
1 parent f419ef6 commit c999f96

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

aws_lambda_powertools/utilities/batch/middlewares.py

+30-4
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,47 @@
77

88
from aws_lambda_powertools.middleware_factory import lambda_handler_decorator
99

10-
from .sqs import PartialSQSProcessor
10+
from .base import BaseProcessor
1111

1212

1313
@lambda_handler_decorator
14-
def partial_sqs_processor(
15-
handler: Callable, event: Dict, context: Dict, record_handler: Callable, processor: PartialSQSProcessor = None
14+
def batch_processor(
15+
handler: Callable, event: Dict, context: Dict, record_handler: Callable, processor: BaseProcessor = None
1616
):
1717
"""
18+
Middleware to handle batch event processing
19+
20+
Parameters
21+
----------
22+
handler: Callable
23+
Lambda's handler
24+
event: Dict
25+
Lambda's Event
26+
context: Dict
27+
Lambda's Context
28+
record_handler: Callable
29+
Callable to process each record from the batch
30+
processor: PartialSQSProcessor
31+
Batch Processor to handle partial failure cases
1832
1933
Examples
2034
--------
35+
**Processes Lambda's event with PartialSQSProcessor**
36+
>>> from aws_lambda_powertools.utilities.batch import batch_processor
37+
>>>
38+
>>> def record_handler(record):
39+
>>> return record["body"]
40+
>>>
41+
>>> @batch_processor(record_handler=record_handler, processor=PartialSQSProcessor)
42+
>>> def handler(event, context):
43+
>>> return {"StatusCode": 200}
44+
45+
Limitations
46+
-----------
47+
* Async batch processors
2148
2249
"""
2350
records = event["Records"]
24-
processor = processor or PartialSQSProcessor()
2551

2652
with processor(records, record_handler) as ctx:
2753
ctx.process()

0 commit comments

Comments
 (0)