UseLambdaRun
Package Trax.Scheduler.LambdaNamespaces Trax.Scheduler.Lambda.Extensions, Trax.Scheduler.Lambda.ConfigurationSource LambdaSchedulerExtensions.cs, LambdaRunOptions.cs, LambdaRunExecutor.cs
Sends synchronous run requests (ITrainExecutionService.RunAsync, and the GraphQL run*
mutations through it) to an AWS Lambda function by direct SDK invocation instead of running the
train in process. The call blocks until the function returns and gives back the train's output. No
public endpoint is involved; access is governed by IAM.
Signature
public static SchedulerConfigurationBuilder UseLambdaRun(
this SchedulerConfigurationBuilder builder,
Action<LambdaRunOptions> configure
)Parameters
| Parameter | Type | Description |
|---|---|---|
configure | Action<LambdaRunOptions> | Sets the function name and client options |
LambdaRunOptions
| Property | Type | Default | Description |
|---|---|---|---|
FunctionName | string | required | The function name, ARN, or partial ARN to invoke |
ConfigureLambdaClient | Action<AmazonLambdaConfig>? | null | Configures the AmazonLambdaConfig the client is built from: region, a LocalStack ServiceURL, and so on |
Retry | LambdaRetryOptions | 5 retries, 1 second base, 30 seconds cap | Retries for transient invocation failures |
SigningKey | byte[]? | null | The key shared with the function's ConfigureRunner, at least 32 bytes. When set, each envelope carries a Signature over its PayloadJson. See Authorization Posture |
Returns
SchedulerConfigurationBuilder, for chaining.
Behavior
- Each run is serialized as a
RemoteRunRequest(train name, input JSON, input type), wrapped in aLambdaEnvelopewithType = Run, and sent withInvocationType.RequestResponse. - A
FunctionErroron the response throwsRemoteRunException(aTrainException) with no public message. ARemoteRunResponsewithIsErrorset throwsRemoteRunExceptioncarrying the remote error details and the runner'sPublicMessage. Otherwise the train's output is returned. - The function's own limits apply: a synchronous response payload is at most 6 MB and a function runs for at most 15 minutes.
- A cancel reaches the function through the database: it sets the run's cancel flag, which the
train sees at its next junction boundary when the function registers
CancellationCheckProvider(throughAddJunctionProgress()). A junction already running is not interrupted. - The scheduler process needs
lambda:InvokeFunctionon the function.
Registered services
| Service | Lifetime | Description |
|---|---|---|
LambdaRunOptions | Singleton | The options |
IAmazonLambda | Singleton | The Lambda client |
IRunExecutor | Scoped | Replaces the default LocalRunExecutor with one that invokes the function and waits for the response |
Example
using Trax.Scheduler.Lambda.Extensions;
services.AddTrax(trax => trax
.AddEffects(effects => effects.UsePostgres(connectionString))
.AddMediator(assembly)
.AddScheduler(scheduler => scheduler
.UseLambdaWorkers(
lambda => lambda.FunctionName = "content-shield-runner",
routing => routing.ForTrain<IReviewContentTrain>())
.UseLambdaRun(lambda =>
{
lambda.FunctionName = "content-shield-runner";
lambda.Retry.MaxRetries = 3;
})));See also
- Run trains on AWS Lambda, setting up the function and the scheduler
- How remote dispatch works, what happens to a run on the way to the function
- UseLambdaWorkers, queued runs on Lambda
- TraxLambdaFunction, the function's base class
- UseRemoteRun, the same over HTTP