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
A complete [Serverless Application Model](https://aws.amazon.com/serverless/sam/) example can be found [here](https://github.com/aws-powertools/powertools-lambda-java/tree/main/examples/powertools-examples-batch) covering all the batch sources.
122
115
116
+
For more information on configuring `ReportBatchItemFailures`, see the details for [SQS](https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html#services-sqs-batchfailurereporting), [Kinesis](https://docs.aws.amazon.com/lambda/latest/dg/with-kinesis.html#services-kinesis-batchfailurereporting), and [DynamoDB Streams](https://docs.aws.amazon.com/lambda/latest/dg/with-ddb.html#services-ddb-batchfailurereporting).
123
117
124
118
125
119
!!! note "You do not need any additional IAM permissions to use this utility, except for what each event source requires."
@@ -150,12 +144,10 @@ see the details for [SQS](https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.
150
144
public SQSBatchResponse handleRequest(SQSEvent sqsEvent, Context context) {
151
145
return handler.processBatch(sqsEvent, context);
152
146
}
153
-
154
-
147
+
155
148
private void processMessage(Product p, Context c) {
156
149
// Process the product
157
150
}
158
-
159
151
}
160
152
```
161
153
@@ -276,7 +268,6 @@ see the details for [SQS](https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.
276
268
private void processMessage(Product p, Context c) {
277
269
// process the product
278
270
}
279
-
280
271
}
281
272
```
282
273
@@ -475,6 +466,46 @@ see the details for [SQS](https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.
475
466
}
476
467
```
477
468
469
+
## Parallel processing
470
+
You can choose to process batch items in parallel using the `BatchMessageHandler#processBatchInParallel()`
471
+
instead of `BatchMessageHandler#processBatch()`. Partial batch failure works the same way but items are processed
472
+
in parallel rather than sequentially.
473
+
474
+
This feature is available for SQS, Kinesis and DynamoDB Streams but cannot be
475
+
used with SQS FIFO. In that case, items will be processed sequentially, even with the `processBatchInParallel` method.
476
+
477
+
!!! warning
478
+
Note that parallel processing is not always better than sequential processing,
479
+
and you should benchmark your code to determine the best approach for your use case.
480
+
481
+
!!! info
482
+
To get more threads available (more vCPUs), you need to increase the amount of memory allocated to your Lambda function.
483
+
While the exact vCPU allocation isn't published, from observing common patterns customers see an allocation of one vCPU per 1024 MB of memory.
484
+
485
+
=== "Example with SQS"
486
+
487
+
```java hl_lines="13"
488
+
public class SqsBatchHandler implements RequestHandler<SQSEvent, SQSBatchResponse> {
489
+
490
+
private final BatchMessageHandler<SQSEvent, SQSBatchResponse> handler;
0 commit comments