File tree 2 files changed +7
-3
lines changed
2 files changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -78,3 +78,7 @@ export type HandlerFunction = (
78
78
data : IEnvironmentData & IHeaderData ,
79
79
callback : CallbackFunction
80
80
) => PromiseLike < unknown > | unknown ;
81
+
82
+ export function isHandlerFunction ( value : any ) : value is HandlerFunction {
83
+ return typeof value === 'function' ;
84
+ }
Original file line number Diff line number Diff line change 8
8
9
9
"use strict" ;
10
10
11
- import { HandlerFunction } from "./Common" ;
11
+ import { HandlerFunction , isHandlerFunction } from "./Common" ;
12
12
import * as Errors from "./Errors" ;
13
13
import RuntimeClient from "./RuntimeClient" ;
14
14
import Runtime from "./Runtime" ;
@@ -18,7 +18,7 @@ import * as UserFunction from "./utils/UserFunction";
18
18
19
19
LogPatch . patchConsole ( ) ;
20
20
21
- export function run ( appRoot : string , handler : string ) : void {
21
+ export function run ( appRoot : string , handler : string | HandlerFunction ) : void {
22
22
if ( ! process . env . AWS_LAMBDA_RUNTIME_API ) {
23
23
throw new Error ( "Missing Runtime API Server configuration." ) ;
24
24
}
@@ -50,7 +50,7 @@ export function run(appRoot: string, handler: string): void {
50
50
BeforeExitListener . reset ( ) ;
51
51
process . on ( "beforeExit" , BeforeExitListener . invoke ) ;
52
52
53
- const handlerFunc = UserFunction . load ( appRoot , handler ) as HandlerFunction ;
53
+ const handlerFunc = isHandlerFunction ( handler ) ? handler : UserFunction . load ( appRoot , handler ) as HandlerFunction ;
54
54
const runtime = new Runtime ( client , handlerFunc , errorCallbacks ) ;
55
55
56
56
runtime . scheduleIteration ( ) ;
You can’t perform that action at this time.
0 commit comments