How it would be possible to run an asynchronous function outside of AWS Lambda handler and make use of its output in the handler function? I need to initialize various DB connections asynchronously before the handler function runs. That way the active DB connections can survive upon container reuse.
Example:
var i = 'immediate start';
setTimeout(function(){
i = 'delayed start';
}, 5000);
module.exports.handler = function (event, context, callback) {
console.log(i);
//outputs `immediate start` whereas I need to have i = `delayed start` here.
}