Skip to content

Commit 445072a

Browse files
committed
Allow passing HandlerFunction to run directly
1 parent 5c92d9b commit 445072a

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/Common/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,7 @@ export type HandlerFunction = (
7878
data: IEnvironmentData & IHeaderData,
7979
callback: CallbackFunction
8080
) => PromiseLike<unknown> | unknown;
81+
82+
export function isHandlerFunction(value: any): value is HandlerFunction {
83+
return typeof value === 'function';
84+
}

src/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
"use strict";
1010

11-
import { HandlerFunction } from "./Common";
11+
import { HandlerFunction, isHandlerFunction } from "./Common";
1212
import * as Errors from "./Errors";
1313
import RuntimeClient from "./RuntimeClient";
1414
import Runtime from "./Runtime";
@@ -18,7 +18,7 @@ import * as UserFunction from "./utils/UserFunction";
1818

1919
LogPatch.patchConsole();
2020

21-
export function run(appRoot: string, handler: string): void {
21+
export function run(appRoot: string, handler: string | HandlerFunction): void {
2222
if (!process.env.AWS_LAMBDA_RUNTIME_API) {
2323
throw new Error("Missing Runtime API Server configuration.");
2424
}
@@ -50,7 +50,7 @@ export function run(appRoot: string, handler: string): void {
5050
BeforeExitListener.reset();
5151
process.on("beforeExit", BeforeExitListener.invoke);
5252

53-
const handlerFunc = UserFunction.load(appRoot, handler) as HandlerFunction;
53+
const handlerFunc = isHandlerFunction(handler) ? handler : UserFunction.load(appRoot, handler) as HandlerFunction;
5454
const runtime = new Runtime(client, handlerFunc, errorCallbacks);
5555

5656
runtime.scheduleIteration();

0 commit comments

Comments
 (0)