Reference

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

ParameterTypeDescription
configureAction<LambdaRunOptions>Sets the function name and client options

LambdaRunOptions

PropertyTypeDefaultDescription
FunctionNamestringrequiredThe function name, ARN, or partial ARN to invoke
ConfigureLambdaClientAction<AmazonLambdaConfig>?nullConfigures the AmazonLambdaConfig the client is built from: region, a LocalStack ServiceURL, and so on
RetryLambdaRetryOptions5 retries, 1 second base, 30 seconds capRetries for transient invocation failures
SigningKeybyte[]?nullThe 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 a LambdaEnvelope with Type = Run, and sent with InvocationType.RequestResponse.
  • A FunctionError on the response throws RemoteRunException (a TrainException) with no public message. A RemoteRunResponse with IsError set throws RemoteRunException carrying the remote error details and the runner's PublicMessage. 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 (through AddJunctionProgress()). A junction already running is not interrupted.
  • The scheduler process needs lambda:InvokeFunction on the function.

Registered services

ServiceLifetimeDescription
LambdaRunOptionsSingletonThe options
IAmazonLambdaSingletonThe Lambda client
IRunExecutorScopedReplaces 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