Class ManyAsyncChildContextExample
java.lang.Object
software.amazon.lambda.durable.DurableHandler<ManyAsyncChildContextExample.Input,ManyAsyncChildContextExample.Output>
software.amazon.lambda.durable.examples.child.ManyAsyncChildContextExample
- All Implemented Interfaces:
com.amazonaws.services.lambda.runtime.RequestStreamHandler
public class ManyAsyncChildContextExample
extends DurableHandler<ManyAsyncChildContextExample.Input,ManyAsyncChildContextExample.Output>
Performance test example demonstrating concurrent async child contexts.
This example tests the SDK's ability to handle many concurrent operations:
- Creates async child context in a loop
- Each child context performs a simple computation in a step
- All results are collected using
DurableFuture.allOf(software.amazon.lambda.durable.DurableFuture<T>...)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordstatic final record -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected DurableConfigTemplate method for creating configuration.handleRequest(ManyAsyncChildContextExample.Input input, DurableContext context) Handle the durable execution.Methods inherited from class software.amazon.lambda.durable.DurableHandler
getConfiguration, handleRequest
-
Constructor Details
-
ManyAsyncChildContextExample
public ManyAsyncChildContextExample()
-
-
Method Details
-
handleRequest
public ManyAsyncChildContextExample.Output handleRequest(ManyAsyncChildContextExample.Input input, DurableContext context) Description copied from class:DurableHandlerHandle the durable execution.- Specified by:
handleRequestin classDurableHandler<ManyAsyncChildContextExample.Input,ManyAsyncChildContextExample.Output> - Parameters:
input- User inputcontext- Durable context for operations- Returns:
- Result
-
createConfiguration
Description copied from class:DurableHandlerTemplate method for creating configuration. Override this method to provide custom DurableExecutionClient, SerDes, or other configuration.The
LambdaDurableFunctionsClientis a wrapper that customers should use to inject their own configuredLambdaClient. This allows full control over AWS SDK configuration including credentials, region, HTTP client, and retry policies.Basic example with custom region and credentials:
@Override protected DurableConfig createConfiguration() { // Create custom Lambda client with specific configuration var lambdaClient = LambdaClient.builder() .region(Region.US_WEST_2) .credentialsProvider(ProfileCredentialsProvider.create("my-profile")) .build(); // Wrap the Lambda client with LambdaDurableFunctionsClient var durableClient = new LambdaDurableFunctionsClient(lambdaClient); return DurableConfig.builder() .withDurableExecutionClient(durableClient) .build(); }Advanced example with AWS CRT HTTP Client for high-performance scenarios:
@Override protected DurableConfig createConfiguration() { // Configure AWS CRT HTTP Client for optimal performance var crtHttpClient = AwsCrtAsyncHttpClient.builder() .maxConcurrency(50) .connectionTimeout(Duration.ofSeconds(30)) .connectionMaxIdleTime(Duration.ofSeconds(60)) .build(); // Create Lambda client with CRT HTTP client var lambdaClient = LambdaClient.builder() .region(Region.US_EAST_1) .credentialsProvider(EnvironmentVariableCredentialsProvider.create()) .httpClient(crtHttpClient) .overrideConfiguration(ClientOverrideConfiguration.builder() .retryPolicy(RetryPolicy.builder() .numRetries(5) .build()) .build()) .build(); // Wrap with LambdaDurableFunctionsClient var durableClient = new LambdaDurableFunctionsClient(lambdaClient); return DurableConfig.builder() .withDurableExecutionClient(durableClient) .withSerDes(customSerDes) // Optional: custom SerDes for user data .withExecutorService(customExecutor) // Optional: custom thread pool .build(); }- Overrides:
createConfigurationin classDurableHandler<ManyAsyncChildContextExample.Input,ManyAsyncChildContextExample.Output> - Returns:
- DurableConfig with desired configuration
-