-
Notifications
You must be signed in to change notification settings - Fork 92
feat: add support for batch execution in parallel with custom Executor #1900
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
phipag
merged 7 commits into
aws-powertools:main
from
visheshruparelia:parallel_execution_custom_executor
Jul 11, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6e7e643
feat: add support for batch execution in parallel with custom Executor
visheshruparelia f06e692
Merge branch 'main' into parallel_execution_custom_executor
phipag ab4b667
Merge branch 'main' into parallel_execution_custom_executor
phipag 850c155
pmd_analyse fix
visheshruparelia 4d0cd06
add docs
visheshruparelia c4361a9
Merge remote-tracking branch 'parent/main' into parallel_execution_cu…
visheshruparelia 5758c71
Update docs/utilities/batch.md
visheshruparelia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...xamples-batch/src/main/java/org/demo/batch/dynamo/DynamoDBStreamBatchHandlerParallel.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.demo.batch.dynamo; | ||
|
||
import com.amazonaws.services.lambda.runtime.Context; | ||
import com.amazonaws.services.lambda.runtime.RequestHandler; | ||
import com.amazonaws.services.lambda.runtime.events.DynamodbEvent; | ||
import com.amazonaws.services.lambda.runtime.events.StreamsEventResponse; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import software.amazon.lambda.powertools.batch.BatchMessageHandlerBuilder; | ||
import software.amazon.lambda.powertools.batch.handler.BatchMessageHandler; | ||
|
||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
|
||
public class DynamoDBStreamBatchHandlerParallel implements RequestHandler<DynamodbEvent, StreamsEventResponse> { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(DynamoDBStreamBatchHandlerParallel.class); | ||
private final BatchMessageHandler<DynamodbEvent, StreamsEventResponse> handler; | ||
private final ExecutorService executor; | ||
|
||
public DynamoDBStreamBatchHandlerParallel() { | ||
handler = new BatchMessageHandlerBuilder() | ||
.withDynamoDbBatchHandler() | ||
.buildWithRawMessageHandler(this::processMessage); | ||
executor = Executors.newFixedThreadPool(2); | ||
} | ||
|
||
@Override | ||
public StreamsEventResponse handleRequest(DynamodbEvent ddbEvent, Context context) { | ||
return handler.processBatchInParallel(ddbEvent, context, executor); | ||
} | ||
|
||
private void processMessage(DynamodbEvent.DynamodbStreamRecord dynamodbStreamRecord) { | ||
LOGGER.info("Processing DynamoDB Stream Record" + dynamodbStreamRecord); | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...ools-examples-batch/src/main/java/org/demo/batch/kinesis/KinesisBatchHandlerParallel.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.demo.batch.kinesis; | ||
|
||
import com.amazonaws.services.lambda.runtime.Context; | ||
import com.amazonaws.services.lambda.runtime.RequestHandler; | ||
import com.amazonaws.services.lambda.runtime.events.KinesisEvent; | ||
import com.amazonaws.services.lambda.runtime.events.StreamsEventResponse; | ||
import org.demo.batch.model.Product; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import software.amazon.lambda.powertools.batch.BatchMessageHandlerBuilder; | ||
import software.amazon.lambda.powertools.batch.handler.BatchMessageHandler; | ||
|
||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
|
||
public class KinesisBatchHandlerParallel implements RequestHandler<KinesisEvent, StreamsEventResponse> { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(KinesisBatchHandlerParallel.class); | ||
private final BatchMessageHandler<KinesisEvent, StreamsEventResponse> handler; | ||
private final ExecutorService executor; | ||
|
||
|
||
public KinesisBatchHandlerParallel() { | ||
handler = new BatchMessageHandlerBuilder() | ||
.withKinesisBatchHandler() | ||
.buildWithMessageHandler(this::processMessage, Product.class); | ||
executor = Executors.newFixedThreadPool(2); | ||
} | ||
|
||
@Override | ||
public StreamsEventResponse handleRequest(KinesisEvent kinesisEvent, Context context) { | ||
return handler.processBatchInParallel(kinesisEvent, context, executor); | ||
} | ||
|
||
private void processMessage(Product p) { | ||
LOGGER.info("Processing product " + p); | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...s/powertools-examples-batch/src/main/java/org/demo/batch/sqs/SqsBatchHandlerParallel.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.demo.batch.sqs; | ||
|
||
import com.amazonaws.services.lambda.runtime.Context; | ||
import com.amazonaws.services.lambda.runtime.RequestHandler; | ||
import com.amazonaws.services.lambda.runtime.events.SQSBatchResponse; | ||
import com.amazonaws.services.lambda.runtime.events.SQSEvent; | ||
import org.demo.batch.model.Product; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import software.amazon.lambda.powertools.batch.BatchMessageHandlerBuilder; | ||
import software.amazon.lambda.powertools.batch.handler.BatchMessageHandler; | ||
import software.amazon.lambda.powertools.logging.Logging; | ||
import software.amazon.lambda.powertools.tracing.Tracing; | ||
|
||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
|
||
public class SqsBatchHandlerParallel extends AbstractSqsBatchHandler implements RequestHandler<SQSEvent, SQSBatchResponse> { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(SqsBatchHandlerParallel.class); | ||
private final BatchMessageHandler<SQSEvent, SQSBatchResponse> handler; | ||
private final ExecutorService executor; | ||
|
||
public SqsBatchHandlerParallel() { | ||
handler = new BatchMessageHandlerBuilder() | ||
.withSqsBatchHandler() | ||
.buildWithMessageHandler(this::processMessage, Product.class); | ||
executor = Executors.newFixedThreadPool(2); | ||
} | ||
|
||
@Logging | ||
@Tracing | ||
@Override | ||
public SQSBatchResponse handleRequest(SQSEvent sqsEvent, Context context) { | ||
LOGGER.info("Processing batch of {} messages", sqsEvent.getRecords().size()); | ||
return handler.processBatchInParallel(sqsEvent, context, executor); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.