Configuration¶
Custom Lambda client¶
By default, the SDK initializes a Lambda client from your environment. You can provide a custom client to control the region, retry settings, credentials, or other options.
Pass a LambdaClient instance via the config parameter of withDurableExecution.
import { LambdaClient } from "@aws-sdk/client-lambda";
import {
DurableContext,
withDurableExecution,
DurableExecutionConfig,
} from "@aws/durable-execution-sdk-js";
const customClient = new LambdaClient({
region: "us-west-2",
maxAttempts: 5,
retryMode: "adaptive",
});
const config: DurableExecutionConfig = { client: customClient };
export const handler = withDurableExecution(
async (event: Record<string, unknown>, context: DurableContext) => {
// Your durable function logic
return { status: "success" };
},
config,
);
Pass a boto3 Lambda client via the boto3_client parameter of @durable_execution. The
client must be a boto3 Lambda client.
import boto3
from botocore.config import Config
from aws_durable_execution_sdk_python import durable_execution, DurableContext
# Create a custom boto3 Lambda client with specific configuration
custom_lambda_client = boto3.client(
'lambda',
config=Config(
retries={'max_attempts': 5, 'mode': 'adaptive'},
connect_timeout=10,
read_timeout=60,
)
)
@durable_execution(boto3_client=custom_lambda_client)
def handler(event: dict, context: DurableContext) -> dict:
# Your durable function logic
return {"status": "success"}
Override createConfiguration() in your DurableHandler subclass and use
DurableConfig.builder().withLambdaClientBuilder(...).
import java.util.Map;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.retries.AdaptiveRetryStrategy;
import software.amazon.awssdk.retries.api.RetryStrategy;
import software.amazon.awssdk.services.lambda.LambdaClient;
import software.amazon.lambda.durable.DurableConfig;
import software.amazon.lambda.durable.DurableContext;
import software.amazon.lambda.durable.DurableHandler;
public class CustomLambdaClient extends DurableHandler<Map<String, Object>, Map<String, Object>> {
@Override
protected DurableConfig createConfiguration() {
RetryStrategy retryStrategy = AdaptiveRetryStrategy.builder()
.maxAttempts(5)
.build();
LambdaClient.Builder lambdaClientBuilder = LambdaClient.builder()
.region(Region.US_WEST_2)
.overrideConfiguration(o -> o.retryStrategy(retryStrategy));
return DurableConfig.builder()
.withLambdaClientBuilder(lambdaClientBuilder)
.build();
}
@Override
public Map<String, Object> handleRequest(Map<String, Object> event, DurableContext context) {
// Your durable function logic
return Map.of("status", "success");
}
}