forked from civicteam/serverless-offline-direct-lambda
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathproxy.js
27 lines (20 loc) · 767 Bytes
/
proxy.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
const serializeError = require('serialize-error');
const path = require('path');
function handler(event, context, callback) {
const [targetHandlerFile, targetHandlerFunction] = event.targetHandler.split(".");
const target = require(path.resolve(__dirname, '../..', targetHandlerFile));
target[targetHandlerFunction](event.body, context, (error, response) => {
if (error) {
// Return Serverless error to AWS sdk
callback(null, {
StatusCode: 500,
FunctionError: 'Handled',
Payload: serializeError(error)
})
} else {
// Return lambda function response to AWS SDK & pass through args from serverless.
callback(null, response)
}
});
}
module.exports.handler = handler;