|
11 | 11 | import sys
|
12 | 12 | from abc import ABC, abstractmethod
|
13 | 13 | from enum import Enum
|
14 |
| -from typing import ( |
15 |
| - Any, |
16 |
| - Awaitable, |
17 |
| - Callable, |
18 |
| - Dict, |
19 |
| - List, |
20 |
| - Optional, |
21 |
| - Tuple, |
22 |
| - Union, |
23 |
| - overload, |
24 |
| -) |
| 14 | +from typing import Any, Callable, Dict, List, Optional, Tuple, Union, overload |
25 | 15 |
|
26 |
| -from aws_lambda_powertools.middleware_factory import lambda_handler_decorator |
27 | 16 | from aws_lambda_powertools.shared import constants
|
28 | 17 | from aws_lambda_powertools.utilities.batch.exceptions import (
|
29 | 18 | BatchProcessingError,
|
@@ -513,51 +502,6 @@ def _process_record(self, record: dict) -> Union[SuccessResponse, FailureRespons
|
513 | 502 | return self.failure_handler(record=data, exception=sys.exc_info())
|
514 | 503 |
|
515 | 504 |
|
516 |
| -@lambda_handler_decorator |
517 |
| -def batch_processor( |
518 |
| - handler: Callable, event: Dict, context: LambdaContext, record_handler: Callable, processor: BatchProcessor |
519 |
| -): |
520 |
| - """ |
521 |
| - Middleware to handle batch event processing |
522 |
| -
|
523 |
| - Parameters |
524 |
| - ---------- |
525 |
| - handler: Callable |
526 |
| - Lambda's handler |
527 |
| - event: Dict |
528 |
| - Lambda's Event |
529 |
| - context: LambdaContext |
530 |
| - Lambda's Context |
531 |
| - record_handler: Callable |
532 |
| - Callable or corutine to process each record from the batch |
533 |
| - processor: BatchProcessor |
534 |
| - Batch Processor to handle partial failure cases |
535 |
| -
|
536 |
| - Examples |
537 |
| - -------- |
538 |
| - **Processes Lambda's event with a BasePartialProcessor** |
539 |
| -
|
540 |
| - >>> from aws_lambda_powertools.utilities.batch import batch_processor, BatchProcessor |
541 |
| - >>> |
542 |
| - >>> def record_handler(record): |
543 |
| - >>> return record["body"] |
544 |
| - >>> |
545 |
| - >>> @batch_processor(record_handler=record_handler, processor=BatchProcessor()) |
546 |
| - >>> def handler(event, context): |
547 |
| - >>> return {"StatusCode": 200} |
548 |
| -
|
549 |
| - Limitations |
550 |
| - ----------- |
551 |
| - * Async batch processors. Use `async_batch_processor` instead. |
552 |
| - """ |
553 |
| - records = event["Records"] |
554 |
| - |
555 |
| - with processor(records, record_handler, lambda_context=context): |
556 |
| - processor.process() |
557 |
| - |
558 |
| - return handler(event, context) |
559 |
| - |
560 |
| - |
561 | 505 | class AsyncBatchProcessor(BasePartialBatchProcessor):
|
562 | 506 | """Process native partial responses from SQS, Kinesis Data Streams, and DynamoDB asynchronously.
|
563 | 507 |
|
@@ -694,52 +638,3 @@ async def _async_process_record(self, record: dict) -> Union[SuccessResponse, Fa
|
694 | 638 | return self._register_model_validation_error_record(record)
|
695 | 639 | except Exception:
|
696 | 640 | return self.failure_handler(record=data, exception=sys.exc_info())
|
697 |
| - |
698 |
| - |
699 |
| -@lambda_handler_decorator |
700 |
| -def async_batch_processor( |
701 |
| - handler: Callable, |
702 |
| - event: Dict, |
703 |
| - context: LambdaContext, |
704 |
| - record_handler: Callable[..., Awaitable[Any]], |
705 |
| - processor: AsyncBatchProcessor, |
706 |
| -): |
707 |
| - """ |
708 |
| - Middleware to handle batch event processing |
709 |
| - Parameters |
710 |
| - ---------- |
711 |
| - handler: Callable |
712 |
| - Lambda's handler |
713 |
| - event: Dict |
714 |
| - Lambda's Event |
715 |
| - context: LambdaContext |
716 |
| - Lambda's Context |
717 |
| - record_handler: Callable[..., Awaitable[Any]] |
718 |
| - Callable to process each record from the batch |
719 |
| - processor: AsyncBatchProcessor |
720 |
| - Batch Processor to handle partial failure cases |
721 |
| - Examples |
722 |
| - -------- |
723 |
| - **Processes Lambda's event with a BasePartialProcessor** |
724 |
| - >>> from aws_lambda_powertools.utilities.batch import async_batch_processor, AsyncBatchProcessor |
725 |
| - >>> |
726 |
| - >>> async def async_record_handler(record): |
727 |
| - >>> payload: str = record.body |
728 |
| - >>> return payload |
729 |
| - >>> |
730 |
| - >>> processor = AsyncBatchProcessor(event_type=EventType.SQS) |
731 |
| - >>> |
732 |
| - >>> @async_batch_processor(record_handler=async_record_handler, processor=processor) |
733 |
| - >>> async def lambda_handler(event, context: LambdaContext): |
734 |
| - >>> return processor.response() |
735 |
| -
|
736 |
| - Limitations |
737 |
| - ----------- |
738 |
| - * Sync batch processors. Use `batch_processor` instead. |
739 |
| - """ |
740 |
| - records = event["Records"] |
741 |
| - |
742 |
| - with processor(records, record_handler, lambda_context=context): |
743 |
| - processor.async_process() |
744 |
| - |
745 |
| - return handler(event, context) |
0 commit comments