Class CustomPollingExample

java.lang.Object
software.amazon.lambda.durable.DurableHandler<GreetingRequest,String>
software.amazon.lambda.durable.examples.CustomPollingExample
All Implemented Interfaces:
com.amazonaws.services.lambda.runtime.RequestStreamHandler

public class CustomPollingExample extends DurableHandler<GreetingRequest,String>
Example demonstrating custom polling strategy configuration.

The polling strategy controls how the SDK polls for async operation results. By default, the SDK uses exponential backoff (1s base, 2x rate, full jitter). This example shows how to customize the polling behavior.

This example configures:

  • Exponential backoff with 500ms base interval
  • 1.5x backoff rate for gentler growth
  • Half jitter to balance between consistency and thundering herd avoidance
  • Constructor Details

    • CustomPollingExample

      public CustomPollingExample()
  • Method Details

    • createConfiguration

      protected DurableConfig createConfiguration()
      Description copied from class: DurableHandler
      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();
       }
       
      Overrides:
      createConfiguration in class DurableHandler<GreetingRequest,String>
      Returns:
      DurableConfig with desired configuration
    • handleRequest

      public String handleRequest(GreetingRequest input, DurableContext context)
      Description copied from class: DurableHandler
      Handle the durable execution.
      Specified by:
      handleRequest in class DurableHandler<GreetingRequest,String>
      Parameters:
      input - User input
      context - Durable context for operations
      Returns:
      Result