-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlambdaRunner.js
41 lines (38 loc) · 987 Bytes
/
lambdaRunner.js
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
32
33
34
35
36
37
38
39
40
41
const {
log,
sendErr,
sendOutput,
installExceptionHandlers,
} = require('./lambda/util');
process.once(
'message',
async ({ module, handlerPath, handlerMethod, payload }) => {
try {
log.info('load', module);
// eslint-disable-next-line
const handlerModule = require(module);
if (!handlerModule[handlerMethod]) {
throw new Error(
`Module : ${handlerPath} does not have export: ${handlerMethod}`,
);
}
log.info('invoke', handlerMethod);
const lambda = handlerModule[handlerMethod];
const context = {};
const lambdaResult = lambda(payload, context, (err, callbackResult) => {
if (err) {
sendErr(err);
} else {
sendOutput(callbackResult);
}
});
if (lambdaResult instanceof Promise) {
sendOutput(await lambdaResult);
}
} catch (err) {
log.error(err);
sendErr(err);
}
},
);
installExceptionHandlers();