-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathrun.js
More file actions
31 lines (24 loc) · 753 Bytes
/
Copy pathrun.js
File metadata and controls
31 lines (24 loc) · 753 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import path from 'path';
import callback from './callback';
import context from './context';
export const run = (
serverless,
options,
requireFn = require,
contextFn = context,
callbackFn = callback
) => {
const { functionName } = options;
const functionObj = serverless.service.getFunction(functionName);
const { handler } = functionObj;
let [filename, handlerFunction] = handler.split('.');
filename = filename + '.js';
const { servicePath } = serverless.config;
const importedHandler = requireFn(path.join(servicePath, filename));
const event = requireFn(path.join(servicePath, 'event.json'));
importedHandler[handlerFunction](
event,
contextFn(functionName, serverless),
callbackFn(serverless)
);
};