Single Lambda Function File Multiple Methods
'use strict'; | |
/* | |
Sample Input: | |
{ | |
"function": "template_function" | |
} | |
*/ | |
module.exports.handler = (event, context, callback) => { | |
context.callbackWaitsForEmptyEventLoop = false; | |
if (typeof event.function === "undefined") { | |
callback(new Error('function name is undefined')); | |
} | |
if (typeof this[event.function] !== "function") { | |
callback(new Error(event.function + ' is not a valid function')); | |
} | |
try { | |
this[event.function](event, callback); | |
} | |
catch (error) { | |
callback(error); | |
} | |
finally { | |
console.log(event.function + ' done'); | |
} | |
}; | |
module.exports.template_function = (event, callback) => { | |
non_export_function('hello'); | |
callback(null, 'Hello from Lambda'); | |
}; | |
var non_export_function = (args) => { | |
console.log('this is a local function'); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment