You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/utilities/batch.md
+3-72
Original file line number
Diff line number
Diff line change
@@ -50,7 +50,7 @@ The remaining sections of the documentation will rely on these samples. For comp
50
50
Function:
51
51
Timeout: 5
52
52
MemorySize: 256
53
-
Runtime: python3.8
53
+
Runtime: python3.9
54
54
Tracing: Active
55
55
Environment:
56
56
Variables:
@@ -97,7 +97,7 @@ The remaining sections of the documentation will rely on these samples. For comp
97
97
Function:
98
98
Timeout: 5
99
99
MemorySize: 256
100
-
Runtime: python3.8
100
+
Runtime: python3.9
101
101
Tracing: Active
102
102
Environment:
103
103
Variables:
@@ -155,7 +155,7 @@ The remaining sections of the documentation will rely on these samples. For comp
155
155
Function:
156
156
Timeout: 5
157
157
MemorySize: 256
158
-
Runtime: python3.8
158
+
Runtime: python3.9
159
159
Tracing: Active
160
160
Environment:
161
161
Variables:
@@ -636,75 +636,6 @@ All records in the batch will be passed to this handler for processing, even if
636
636
All processing logic will and should be performed by the `record_handler` function.
637
637
638
638
639
-
<!-- ### IAM Permissions
640
-
641
-
Before your use this utility, your AWS Lambda function must have `sqs:DeleteMessageBatch` permission to delete successful messages directly from the queue.
642
-
643
-
> Example using AWS Serverless Application Model (SAM)
644
-
645
-
=== "template.yml"
646
-
647
-
```yaml hl_lines="2-3 12-15"
648
-
Resources:
649
-
MyQueue:
650
-
Type: AWS::SQS::Queue
651
-
652
-
HelloWorldFunction:
653
-
Type: AWS::Serverless::Function
654
-
Properties:
655
-
Runtime: python3.8
656
-
Environment:
657
-
Variables:
658
-
POWERTOOLS_SERVICE_NAME: example
659
-
Policies:
660
-
- SQSPollerPolicy:
661
-
QueueName:
662
-
!GetAtt MyQueue.QueueName
663
-
```
664
-
665
-
### Processing messages from SQS
666
-
667
-
You can use either `sqs_batch_processor` decorator, or `PartialSQSProcessor` as a context manager if you'd like access to the processed results.
668
-
669
-
You need to create a function to handle each record from the batch - We call it `record_handler` from here on.
670
-
671
-
=== "Decorator"
672
-
673
-
```python hl_lines="3 6"
674
-
from aws_lambda_powertools.utilities.batch import sqs_batch_processor
from aws_lambda_powertools.utilities.batch import PartialSQSProcessor
687
-
688
-
def record_handler(record):
689
-
return_value = do_something_with(record["body"])
690
-
return return_value
691
-
692
-
def lambda_handler(event, context):
693
-
records = event["Records"]
694
-
processor = PartialSQSProcessor()
695
-
696
-
with processor(records, record_handler) as proc:
697
-
result = proc.process() # Returns a list of all results from record_handler
698
-
699
-
return result
700
-
```
701
-
702
-
!!! tip
703
-
**Any non-exception/successful return from your record handler function** will instruct both decorator and context manager to queue up each individual message for deletion.
704
-
705
-
If the entire batch succeeds, we let Lambda to proceed in deleting the records from the queue for cost reasons. -->
0 commit comments