-
Notifications
You must be signed in to change notification settings - Fork 227
/
_lambda-handler.js
40 lines (35 loc) · 1.11 KB
/
_lambda-handler.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
/*
* Copyright Elasticsearch B.V. and other contributors where applicable.
* Licensed under the BSD 2-Clause License; you may not use this file except in
* compliance with the BSD 2-Clause License.
*/
'use strict';
const propwrap = require('../../propwrap');
/**
* Return a patch handler, `function (module, agent, options)`, that will patch
* the Lambda handler function at the given property path.
*
* For example, a Lambda _HANDLER=index.handler indicates that a file "index.js"
* has a `handler` export that is the Lambda handler function. In this case
* `module` will be the imported "index.js" module and `propPath` will be
* "handler".
*/
function createLambdaPatcher(propPath) {
return function lambdaHandlerPatcher(module, agent, { enabled }) {
if (!enabled) {
return module;
}
try {
const newMod = propwrap.wrap(module, propPath, (orig) => {
return agent.lambda(orig);
});
return newMod;
} catch (wrapErr) {
agent.logger.warn('could not wrap lambda handler: %s', wrapErr);
return module;
}
};
}
module.exports = {
createLambdaPatcher,
};