@temporalio/lambda-worker 1.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +158 -0
- package/lib/config.d.ts +12 -0
- package/lib/config.js +69 -0
- package/lib/config.js.map +1 -0
- package/lib/defaults.d.ts +16 -0
- package/lib/defaults.js +29 -0
- package/lib/defaults.js.map +1 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +8 -0
- package/lib/index.js.map +1 -0
- package/lib/json-logger.d.ts +29 -0
- package/lib/json-logger.js +65 -0
- package/lib/json-logger.js.map +1 -0
- package/lib/lambda-worker.d.ts +51 -0
- package/lib/lambda-worker.js +141 -0
- package/lib/lambda-worker.js.map +1 -0
- package/lib/logger-factory.d.ts +10 -0
- package/lib/logger-factory.js +28 -0
- package/lib/logger-factory.js.map +1 -0
- package/lib/otel.d.ts +83 -0
- package/lib/otel.js +103 -0
- package/lib/otel.js.map +1 -0
- package/lib/types.d.ts +70 -0
- package/lib/types.js +3 -0
- package/lib/types.js.map +1 -0
- package/package.json +86 -0
- package/src/config.ts +53 -0
- package/src/defaults.ts +30 -0
- package/src/index.ts +3 -0
- package/src/json-logger.ts +69 -0
- package/src/lambda-worker.ts +190 -0
- package/src/logger-factory.ts +27 -0
- package/src/otel.ts +127 -0
- package/src/types.ts +78 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { setTimeout } from 'timers/promises';
|
|
2
|
+
import type { Context } from 'aws-lambda';
|
|
3
|
+
import type { WorkerDeploymentVersion, Logger } from '@temporalio/common';
|
|
4
|
+
import {
|
|
5
|
+
type WorkerOptions,
|
|
6
|
+
type NativeConnectionOptions,
|
|
7
|
+
type RuntimeOptions,
|
|
8
|
+
NativeConnection,
|
|
9
|
+
Worker,
|
|
10
|
+
Runtime,
|
|
11
|
+
} from '@temporalio/worker';
|
|
12
|
+
import type { ClientConnectConfig } from '@temporalio/envconfig';
|
|
13
|
+
import {
|
|
14
|
+
LAMBDA_WORKER_DEFAULTS,
|
|
15
|
+
DEFAULT_SHUTDOWN_DEADLINE_BUFFER_MS,
|
|
16
|
+
MINIMUM_WORK_TIME_MS,
|
|
17
|
+
WARN_WORK_TIME_MS,
|
|
18
|
+
} from './defaults';
|
|
19
|
+
import { loadLambdaClientConnectConfig } from './config';
|
|
20
|
+
import { PowertoolsLoggerAdapter } from './json-logger';
|
|
21
|
+
import { makePowertoolsLogger } from './logger-factory';
|
|
22
|
+
import type { LambdaWorkerConfig, LambdaHandler } from './types';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @internal Dependency injection interface for testing.
|
|
26
|
+
*/
|
|
27
|
+
export interface WorkerDeps {
|
|
28
|
+
connect: (options: NativeConnectionOptions) => Promise<{ close(): Promise<void> }>;
|
|
29
|
+
createWorker: (options: WorkerOptions) => Promise<{ runUntil(p: Promise<void>): Promise<void> }>;
|
|
30
|
+
loadConnectConfig: () => ClientConnectConfig;
|
|
31
|
+
installRuntime: (options: RuntimeOptions) => void;
|
|
32
|
+
getLogger: () => Logger;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const defaultDeps: WorkerDeps = {
|
|
36
|
+
connect: (opts) => NativeConnection.connect(opts),
|
|
37
|
+
createWorker: (opts) => Worker.create(opts),
|
|
38
|
+
loadConnectConfig: loadLambdaClientConnectConfig,
|
|
39
|
+
installRuntime: (opts) => Runtime.install(opts),
|
|
40
|
+
getLogger: () => Runtime.instance().logger,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Create an AWS Lambda handler that runs a Temporal Worker for the duration of each invocation.
|
|
45
|
+
*
|
|
46
|
+
* The handler connects to Temporal, creates a Worker, polls for tasks until the Lambda deadline
|
|
47
|
+
* approaches, then gracefully shuts down and runs any registered shutdown hooks.
|
|
48
|
+
*
|
|
49
|
+
* Calling this more than once will result in an error.
|
|
50
|
+
*
|
|
51
|
+
* @param version - The worker deployment version. Worker versioning is always enabled.
|
|
52
|
+
* @param configure - Callback to customize the pre-populated {@link LambdaWorkerConfig}.
|
|
53
|
+
* Mutate the config object directly (e.g., set `config.workerOptions.taskQueue`).
|
|
54
|
+
* @returns A Lambda handler function.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* import { runWorker } from '@temporalio/lambda-worker';
|
|
59
|
+
* import * as activities from './activities';
|
|
60
|
+
*
|
|
61
|
+
* export const handler = runWorker(
|
|
62
|
+
* { buildId: 'v1.0.0', deploymentName: 'my-service' },
|
|
63
|
+
* (config) => {
|
|
64
|
+
* config.workerOptions.taskQueue = 'my-task-queue';
|
|
65
|
+
* config.workerOptions.workflowBundle = { code: require('./workflow-bundle.js') };
|
|
66
|
+
* config.workerOptions.activities = activities;
|
|
67
|
+
* },
|
|
68
|
+
* );
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export function runWorker(
|
|
72
|
+
version: WorkerDeploymentVersion,
|
|
73
|
+
configure: (config: LambdaWorkerConfig) => void
|
|
74
|
+
): LambdaHandler {
|
|
75
|
+
return _runWorkerInternal(version, configure, defaultDeps);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @internal Testable implementation of runWorker with injected dependencies.
|
|
80
|
+
*/
|
|
81
|
+
export function _runWorkerInternal(
|
|
82
|
+
version: WorkerDeploymentVersion,
|
|
83
|
+
configure: (config: LambdaWorkerConfig) => void,
|
|
84
|
+
deps: WorkerDeps
|
|
85
|
+
): LambdaHandler {
|
|
86
|
+
const config: LambdaWorkerConfig = {
|
|
87
|
+
workerOptions: {
|
|
88
|
+
...LAMBDA_WORKER_DEFAULTS,
|
|
89
|
+
workerDeploymentOptions: {
|
|
90
|
+
defaultVersioningBehavior: 'PINNED',
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
runtimeOptions: {
|
|
94
|
+
logger: makePowertoolsLogger(),
|
|
95
|
+
shutdownSignals: [],
|
|
96
|
+
},
|
|
97
|
+
shutdownHooks: [],
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const envTaskQueue = process.env['TEMPORAL_TASK_QUEUE'];
|
|
101
|
+
if (envTaskQueue) {
|
|
102
|
+
config.workerOptions.taskQueue = envTaskQueue;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const connectConfig = deps.loadConnectConfig();
|
|
106
|
+
config.connectionOptions = { ...connectConfig.connectionOptions };
|
|
107
|
+
config.namespace = connectConfig.namespace || 'default';
|
|
108
|
+
|
|
109
|
+
configure(config);
|
|
110
|
+
|
|
111
|
+
const taskQueue = config.workerOptions.taskQueue;
|
|
112
|
+
if (!taskQueue) {
|
|
113
|
+
throw new Error(
|
|
114
|
+
'taskQueue is required: set config.workerOptions.taskQueue in the configure callback ' +
|
|
115
|
+
'or set the TEMPORAL_TASK_QUEUE environment variable'
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Install the Runtime with the (possibly user-modified) options
|
|
120
|
+
deps.installRuntime(config.runtimeOptions);
|
|
121
|
+
|
|
122
|
+
const shutdownDeadlineBufferMs = config.shutdownDeadlineBufferMs ?? DEFAULT_SHUTDOWN_DEADLINE_BUFFER_MS;
|
|
123
|
+
|
|
124
|
+
const runtimeLogger = config.runtimeOptions.logger;
|
|
125
|
+
|
|
126
|
+
return async (_event: unknown, context: Context): Promise<void> => {
|
|
127
|
+
if (runtimeLogger instanceof PowertoolsLoggerAdapter) {
|
|
128
|
+
runtimeLogger.addContext(context);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const logger = deps.getLogger();
|
|
132
|
+
const remainingMs = context.getRemainingTimeInMillis();
|
|
133
|
+
const workTimeMs = remainingMs - shutdownDeadlineBufferMs;
|
|
134
|
+
|
|
135
|
+
if (workTimeMs <= MINIMUM_WORK_TIME_MS) {
|
|
136
|
+
throw new Error(
|
|
137
|
+
`Insufficient time for Lambda worker: ${remainingMs}ms remaining, ` +
|
|
138
|
+
`${shutdownDeadlineBufferMs}ms shutdown buffer, only ${workTimeMs}ms work time ` +
|
|
139
|
+
`(minimum: ${MINIMUM_WORK_TIME_MS}ms)`
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
if (workTimeMs < WARN_WORK_TIME_MS) {
|
|
143
|
+
logger.warn('Low work time available for Lambda worker', {
|
|
144
|
+
remainingMs,
|
|
145
|
+
shutdownDeadlineBufferMs,
|
|
146
|
+
workTimeMs,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const identity = `${context.awsRequestId}@${context.invokedFunctionArn}`;
|
|
151
|
+
|
|
152
|
+
let connection;
|
|
153
|
+
try {
|
|
154
|
+
connection = await deps.connect(config.connectionOptions ?? {});
|
|
155
|
+
const workerOptions: WorkerOptions = {
|
|
156
|
+
...config.workerOptions,
|
|
157
|
+
taskQueue,
|
|
158
|
+
connection: connection as NativeConnection,
|
|
159
|
+
namespace: config.namespace,
|
|
160
|
+
identity,
|
|
161
|
+
workerDeploymentOptions: {
|
|
162
|
+
version,
|
|
163
|
+
useWorkerVersioning: true,
|
|
164
|
+
defaultVersioningBehavior:
|
|
165
|
+
config.workerOptions.workerDeploymentOptions?.defaultVersioningBehavior ?? 'PINNED',
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
const worker = await deps.createWorker(workerOptions);
|
|
170
|
+
|
|
171
|
+
await worker.runUntil(setTimeout(workTimeMs));
|
|
172
|
+
} finally {
|
|
173
|
+
for (const hook of config.shutdownHooks) {
|
|
174
|
+
try {
|
|
175
|
+
await hook();
|
|
176
|
+
} catch (err) {
|
|
177
|
+
logger.error('Lambda worker shutdown hook failed', { error: err });
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
try {
|
|
182
|
+
if (connection) {
|
|
183
|
+
await connection.close();
|
|
184
|
+
}
|
|
185
|
+
} catch (err) {
|
|
186
|
+
logger.error('Failed to close Temporal connection', { error: err });
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Logger } from '@temporalio/worker';
|
|
2
|
+
import { PowertoolsLoggerAdapter } from './json-logger';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Create a Powertools-based logger for the Lambda worker.
|
|
6
|
+
*
|
|
7
|
+
* If `@aws-lambda-powertools/logger` is installed, returns a
|
|
8
|
+
* {@link PowertoolsLoggerAdapter} wrapping a Powertools Logger.
|
|
9
|
+
* Otherwise, returns `undefined`, causing the Runtime to fall back
|
|
10
|
+
* to its default logger.
|
|
11
|
+
*/
|
|
12
|
+
export function makePowertoolsLogger(): Logger | undefined {
|
|
13
|
+
try {
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
15
|
+
const { Logger: PtLogger } = require('@aws-lambda-powertools/logger');
|
|
16
|
+
return new PowertoolsLoggerAdapter(
|
|
17
|
+
new PtLogger({
|
|
18
|
+
serviceName: process.env['AWS_LAMBDA_FUNCTION_NAME'] ?? 'temporal-lambda-worker',
|
|
19
|
+
})
|
|
20
|
+
);
|
|
21
|
+
} catch (err) {
|
|
22
|
+
if ((err as NodeJS.ErrnoException).code !== 'MODULE_NOT_FOUND') {
|
|
23
|
+
throw err;
|
|
24
|
+
}
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
}
|
package/src/otel.ts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-grpc';
|
|
2
|
+
import { Resource } from '@opentelemetry/resources';
|
|
3
|
+
import { SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base';
|
|
4
|
+
import { OpenTelemetryPlugin } from '@temporalio/interceptors-opentelemetry';
|
|
5
|
+
import type { LambdaWorkerConfig } from './types';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Options for the batteries-included OTel setup.
|
|
9
|
+
*/
|
|
10
|
+
export interface OtelOptions {
|
|
11
|
+
/**
|
|
12
|
+
* OTLP gRPC collector endpoint for Core SDK metrics and SDK trace span export.
|
|
13
|
+
* Defaults to `OTEL_EXPORTER_OTLP_ENDPOINT` env var, then `grpc://localhost:4317`.
|
|
14
|
+
*/
|
|
15
|
+
endpoint?: string;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* OTel service name. Falls back to `OTEL_SERVICE_NAME` env var,
|
|
19
|
+
* then `AWS_LAMBDA_FUNCTION_NAME`, then `'temporal-lambda-worker'`.
|
|
20
|
+
*/
|
|
21
|
+
serviceName?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Configure OpenTelemetry for a Lambda worker:
|
|
26
|
+
*
|
|
27
|
+
* - Registers Temporal SDK interceptors (`@temporalio/interceptors-opentelemetry`) for
|
|
28
|
+
* tracing Workflow, Activity, and Nexus calls via the `OpenTelemetryPlugin`.
|
|
29
|
+
* - Configures Core-side telemetry so the Temporal Rust SDK exports its own metrics
|
|
30
|
+
* (workflow/activity task latencies, poll counts, etc.) via OTLP.
|
|
31
|
+
*
|
|
32
|
+
* Node.js-side Lambda auto-instrumentation (root spans, HTTP calls, etc.) is handled
|
|
33
|
+
* by the ADOT JS Lambda layer — this function does not set up a separate `NodeSDK` or
|
|
34
|
+
* `TracerProvider` to avoid conflicting with the layer.
|
|
35
|
+
*
|
|
36
|
+
* **Required AWS setup**: attach both Lambda layers:
|
|
37
|
+
*
|
|
38
|
+
* 1. [ADOT JavaScript layer](https://aws-otel.github.io/docs/getting-started/lambda/lambda-js)
|
|
39
|
+
* — auto-instruments the handler and exports Node.js-side traces.
|
|
40
|
+
* 2. [ADOT Collector layer](https://aws-otel.github.io/docs/getting-started/lambda)
|
|
41
|
+
* (`aws-otel-collector-amd64`) — runs the OTel Collector as a Lambda extension,
|
|
42
|
+
* receiving Core SDK metrics via OTLP on `localhost:4317` and forwarding them to
|
|
43
|
+
* CloudWatch/X-Ray.
|
|
44
|
+
*
|
|
45
|
+
* Then set these environment variables:
|
|
46
|
+
*
|
|
47
|
+
* - `AWS_LAMBDA_EXEC_WRAPPER=/opt/otel-instrument`
|
|
48
|
+
* - `OPENTELEMETRY_COLLECTOR_CONFIG_URI=/var/task/otel-collector-config.yaml`
|
|
49
|
+
*
|
|
50
|
+
* **Important**: When pre-bundling Workflow code with `bundleWorkflowCode()`, you must
|
|
51
|
+
* pass `makeOtelPlugin()` so Workflow interceptor modules are included in the bundle.
|
|
52
|
+
* See {@link makeOtelPlugin}.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* import { runWorker } from '@temporalio/lambda-worker';
|
|
57
|
+
* import { applyDefaults } from '@temporalio/lambda-worker/otel';
|
|
58
|
+
*
|
|
59
|
+
* export const handler = runWorker(version, (config) => {
|
|
60
|
+
* applyDefaults(config);
|
|
61
|
+
* config.workerOptions.taskQueue = 'my-queue';
|
|
62
|
+
* // ...
|
|
63
|
+
* });
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export function applyDefaults(config: LambdaWorkerConfig, options?: OtelOptions): void {
|
|
67
|
+
const endpoint = options?.endpoint ?? process.env['OTEL_EXPORTER_OTLP_ENDPOINT'] ?? 'grpc://localhost:4317';
|
|
68
|
+
|
|
69
|
+
// Configure Core-side telemetry so the Temporal Rust SDK exports its own
|
|
70
|
+
// metrics (workflow/activity task latencies, poll counts, etc.) to the
|
|
71
|
+
// standalone ADOT collector extension running as a Lambda layer.
|
|
72
|
+
config.runtimeOptions.telemetryOptions = {
|
|
73
|
+
...config.runtimeOptions.telemetryOptions,
|
|
74
|
+
metrics: {
|
|
75
|
+
otel: {
|
|
76
|
+
url: endpoint,
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// Set up the OpenTelemetry plugin for Temporal SDK interceptors.
|
|
82
|
+
// This traces Workflow, Activity, and Nexus calls.
|
|
83
|
+
const { plugin, spanProcessor } = makeOtelPlugin(endpoint, options?.serviceName);
|
|
84
|
+
config.workerOptions.plugins = [...(config.workerOptions.plugins ?? []), plugin];
|
|
85
|
+
|
|
86
|
+
config.shutdownHooks.push(async () => {
|
|
87
|
+
await spanProcessor.forceFlush();
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// TODO: Spans don't automatically get parented to the lambda invocation span, and it's not clear
|
|
92
|
+
// how we'd make that work, but is worth doing in the future if possible.
|
|
93
|
+
/**
|
|
94
|
+
* Create the OpenTelemetry plugin for use with `Worker.create()` and
|
|
95
|
+
* `bundleWorkflowCode()`. When pre-bundling workflows, pass the returned plugin
|
|
96
|
+
* to `bundleWorkflowCode({ plugins: [plugin] })` so workflow interceptor modules
|
|
97
|
+
* are included in the bundle.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts
|
|
101
|
+
* import { bundleWorkflowCode } from '@temporalio/worker';
|
|
102
|
+
* import { makeOtelPlugin } from '@temporalio/lambda-worker/otel';
|
|
103
|
+
*
|
|
104
|
+
* const { plugin } = makeOtelPlugin();
|
|
105
|
+
* const bundle = await bundleWorkflowCode({
|
|
106
|
+
* workflowsPath: require.resolve('./workflows'),
|
|
107
|
+
* plugins: [plugin],
|
|
108
|
+
* });
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
export function makeOtelPlugin(
|
|
112
|
+
endpoint?: string,
|
|
113
|
+
serviceName?: string
|
|
114
|
+
): { plugin: OpenTelemetryPlugin; spanProcessor: SimpleSpanProcessor } {
|
|
115
|
+
const resolvedEndpoint = endpoint ?? process.env['OTEL_EXPORTER_OTLP_ENDPOINT'] ?? 'grpc://localhost:4317';
|
|
116
|
+
const resolvedServiceName =
|
|
117
|
+
serviceName ??
|
|
118
|
+
process.env['OTEL_SERVICE_NAME'] ??
|
|
119
|
+
process.env['AWS_LAMBDA_FUNCTION_NAME'] ??
|
|
120
|
+
'temporal-lambda-worker';
|
|
121
|
+
|
|
122
|
+
const resource = new Resource({ 'service.name': resolvedServiceName });
|
|
123
|
+
const traceExporter = new OTLPTraceExporter({ url: resolvedEndpoint });
|
|
124
|
+
const spanProcessor = new SimpleSpanProcessor(traceExporter);
|
|
125
|
+
|
|
126
|
+
return { plugin: new OpenTelemetryPlugin({ resource, spanProcessor }), spanProcessor };
|
|
127
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { Context } from 'aws-lambda';
|
|
2
|
+
import type { VersioningBehavior } from '@temporalio/common';
|
|
3
|
+
import type { WorkerOptions, NativeConnectionOptions, RuntimeOptions } from '@temporalio/worker';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A function called after the worker stops on each invocation.
|
|
7
|
+
* Errors are caught, logged, and do not prevent subsequent hooks from running.
|
|
8
|
+
*/
|
|
9
|
+
export type ShutdownHook = () => Promise<void> | void;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Configuration object passed to the {@link runWorker} configure callback.
|
|
13
|
+
*
|
|
14
|
+
* Pre-populated with Lambda-tuned defaults. You should set `workerOptions.taskQueue`, register
|
|
15
|
+
* activities/workflows, and override any defaults as needed.
|
|
16
|
+
*/
|
|
17
|
+
export interface LambdaWorkerConfig {
|
|
18
|
+
/**
|
|
19
|
+
* Worker options, pre-populated with Lambda-appropriate defaults.
|
|
20
|
+
*
|
|
21
|
+
* You must set at least `taskQueue` (or set the `TEMPORAL_TASK_QUEUE` env var). Typically you'll
|
|
22
|
+
* also set `activities` and `workflowBundle` (prefer pre-bundled workflows over `workflowsPath`
|
|
23
|
+
* to avoid bundling overhead on Lambda cold starts).
|
|
24
|
+
*
|
|
25
|
+
* The following fields are managed by settings elsewhere and will be overridden per-invocation:
|
|
26
|
+
* `connection`, `namespace`, `identity`.
|
|
27
|
+
*/
|
|
28
|
+
workerOptions: Partial<Omit<WorkerOptions, 'connection' | 'namespace' | 'identity' | 'workerDeploymentOptions'>> & {
|
|
29
|
+
/**
|
|
30
|
+
* `version` and `useWorkerVersioning` are managed by `runWorker` and cannot be set here.
|
|
31
|
+
*
|
|
32
|
+
* @default { defaultVersioningBehavior: 'PINNED' }
|
|
33
|
+
*/
|
|
34
|
+
workerDeploymentOptions?: {
|
|
35
|
+
defaultVersioningBehavior?: VersioningBehavior;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Connection options overrides, merged on top of values loaded via envconfig.
|
|
41
|
+
*/
|
|
42
|
+
connectionOptions?: Partial<NativeConnectionOptions>;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Namespace override. Falls back to the envconfig-loaded value, then `"default"`.
|
|
46
|
+
*/
|
|
47
|
+
namespace?: string;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Time in milliseconds before the Lambda invocation deadline at which the worker
|
|
51
|
+
* begins its shutdown sequence (graceful drain + shutdown hooks).
|
|
52
|
+
*
|
|
53
|
+
* @default 7000 (5s graceful shutdown + 2s margin)
|
|
54
|
+
*/
|
|
55
|
+
shutdownDeadlineBufferMs?: number;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Options for the Temporal {@link Runtime} singleton, installed automatically by `runWorker`.
|
|
59
|
+
*
|
|
60
|
+
* Pre-populated with a Powertools JSON logger (if `@aws-lambda-powertools/logger` is installed)
|
|
61
|
+
* and `shutdownSignals: []` (Lambda manages its own lifecycle).
|
|
62
|
+
*
|
|
63
|
+
* Override `runtimeOptions.logger` to use a custom logger, or modify `runtimeOptions.telemetryOptions`
|
|
64
|
+
* to configure Core-side telemetry.
|
|
65
|
+
*/
|
|
66
|
+
runtimeOptions: RuntimeOptions;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Hooks executed in order after the worker stops on each invocation.
|
|
70
|
+
* Each hook's errors are caught and logged without preventing subsequent hooks.
|
|
71
|
+
*/
|
|
72
|
+
shutdownHooks: ShutdownHook[];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The Lambda handler function returned by {@link runWorker}.
|
|
77
|
+
*/
|
|
78
|
+
export type LambdaHandler = (event: unknown, context: Context) => Promise<void>;
|