Package software.amazon.lambda.durable
Class DurableHandler<I,O>
java.lang.Object
software.amazon.lambda.durable.DurableHandler<I,O>
- All Implemented Interfaces:
com.amazonaws.services.lambda.runtime.RequestStreamHandler
- Direct Known Subclasses:
CallbackExample,ChildContextExample,CustomConfigExample,CustomPollingExample,ErrorHandlingExample,GenericInputOutputExample,GenericTypesExample,LoggingExample,ManyAsyncChildContextExample,ManyAsyncStepsExample,NoopExample,RetryExample,RetryInProcessExample,SimpleInvokeExample,SimpleStepExample,WaitAsyncExample,WaitAtLeastExample,WaitAtLeastInProcessExample,WaitExample
public abstract class DurableHandler<I,O>
extends Object
implements com.amazonaws.services.lambda.runtime.RequestStreamHandler
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected DurableConfigTemplate method for creating configuration.static com.fasterxml.jackson.databind.ObjectMapperCreates ObjectMapper for DAR backend communication (internal use only).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)
-
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 - Specified by:
handleRequestin interfacecom.amazonaws.services.lambda.runtime.RequestStreamHandler- Throws:
IOException
-
handleRequest
Handle the durable execution.- Parameters:
input- User inputcontext- Durable context for operations- Returns:
- Result
-
createObjectMapper
public static com.fasterxml.jackson.databind.ObjectMapper createObjectMapper()Creates ObjectMapper for DAR backend communication (internal use only). This is for INTERNAL use only - handles Lambda Durable Functions backend protocol.Customer-facing serialization uses SerDes from DurableConfig.
- Returns:
- Configured ObjectMapper for durable backend communication
-