Package software.amazon.lambda.durable
Class DurableHandler<I,O>
java.lang.Object
software.amazon.lambda.durable.DurableHandler<I,O>
- Type Parameters:
I- the input typeO- the output type
- All Implemented Interfaces:
com.amazonaws.services.lambda.runtime.RequestStreamHandler
- Direct Known Subclasses:
CallbackExample,ChildContextExample,ComplexMapExample,ConcurrentWaitForConditionExample,CustomConfigExample,CustomPollingExample,DeserializationFailedMapExample,DeserializationFailedParallelExample,DeserializationFailureExample,ErrorHandlingExample,GenericInputOutputExample,GenericTypesExample,LoggingExample,ManyAsyncChildContextExample,ManyAsyncStepsExample,NoopExample,ParallelExample,ParallelFailureToleranceExample,ParallelWithWaitExample,RetryExample,RetryInProcessExample,SimpleInvokeExample,SimpleMapExample,SimpleStepExample,WaitAsyncExample,WaitAtLeastExample,WaitAtLeastInProcessExample,WaitExample,WaitForCallbackFailedExample,WaitForConditionExample
public abstract class DurableHandler<I,O>
extends Object
implements com.amazonaws.services.lambda.runtime.RequestStreamHandler
Abstract base class for Lambda handlers that use durable execution.
Extend this class and implement handleRequest(Object, DurableContext) to build resilient, multi-step
workflows. The handler automatically manages checkpoint-and-replay, input deserialization, and communication with the
Lambda Durable Functions backend.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected DurableConfigTemplate method for creating configuration.Gets the configuration used by this handler.abstract OhandleRequest(I input, DurableContext context) Handle the durable execution.final voidhandleRequest(InputStream inputStream, OutputStream outputStream, com.amazonaws.services.lambda.runtime.Context context) Reads the request, executes the durable function handler and writes the response
-
Constructor Details
-
DurableHandler
protected DurableHandler()
-
-
Method Details
-
getConfiguration
Gets the configuration used by this handler. This allows test frameworks and other tools to access the handler's configuration for testing purposes.DurableConfig is immutable.
- Returns:
- The DurableConfig instance used by this handler
-
createConfiguration
Template 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(); }- Returns:
- DurableConfig with desired configuration
-
handleRequest
public final void handleRequest(InputStream inputStream, OutputStream outputStream, com.amazonaws.services.lambda.runtime.Context context) throws IOException Reads the request, executes the durable function handler and writes the response- Specified by:
handleRequestin interfacecom.amazonaws.services.lambda.runtime.RequestStreamHandler- Parameters:
inputStream- the input streamoutputStream- the output streamcontext- the Lambda context- Throws:
IOException- thrown when serialize/deserialize fails
-
handleRequest
Handle the durable execution.- Parameters:
input- User inputcontext- Durable context for operations- Returns:
- Result
-