Class DurableHandler<I,O>

java.lang.Object
software.amazon.lambda.durable.DurableHandler<I,O>
Type Parameters:
I - the input type
O - 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 Details

    • DurableHandler

      protected DurableHandler()
  • Method Details

    • getConfiguration

      public DurableConfig 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

      protected DurableConfig createConfiguration()
      Template method for creating configuration. Override this method to provide custom DurableExecutionClient, SerDes, or other configuration.

      The LambdaDurableFunctionsClient is a wrapper that customers should use to inject their own configured LambdaClient. 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:
      handleRequest in interface com.amazonaws.services.lambda.runtime.RequestStreamHandler
      Parameters:
      inputStream - the input stream
      outputStream - the output stream
      context - the Lambda context
      Throws:
      IOException - thrown when serialize/deserialize fails
    • handleRequest

      public abstract O handleRequest(I input, DurableContext context)
      Handle the durable execution.
      Parameters:
      input - User input
      context - Durable context for operations
      Returns:
      Result