Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions wrappers/cron.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";

const wrapAsAsync = require("./wrapAsAsync");

let cachedHandler;
module.exports = function(configOverride, botHandler) {
Expand Down Expand Up @@ -100,7 +101,7 @@ module.exports = function(configOverride, botHandler) {
}

Object.assign(config, configOverride);
return function(event, context, callback) {
return wrapAsAsync(function(event, context, callback) {
context.callbackWaitsForEmptyEventLoop = false;
context.resources = process.resources;
context.botId = event.botId || botId;
Expand Down Expand Up @@ -252,6 +253,6 @@ module.exports = function(configOverride, botHandler) {
}
});
}
};
});
};
module.exports.CronWrapper = module.exports;
5 changes: 3 additions & 2 deletions wrappers/fanout.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

const wrapAsAsync = require("./wrapAsAsync");
const { Lambda } = require("@aws-sdk/client-lambda");
const async = require("async");
const eventIdFormat = "[z/]YYYY/MM/DD/HH/mm/";
Expand Down Expand Up @@ -110,7 +111,7 @@ const fanoutFactory = (handler, eventPartition, opts = {}) => {


logger.log("Fanout Return", process.env.FANOUT_iid, process.env.FANOUT_icount, process.env.FANOUT_maxeid);
return (event, context, callback) => {
return wrapAsAsync((event, context, callback) => {

cronData = event.__cron || {};

Expand Down Expand Up @@ -199,7 +200,7 @@ const fanoutFactory = (handler, eventPartition, opts = {}) => {
return callback(err);
});
}
};
});
};

function callCheckpointOnResponses(leoBotCheckpoint, callback) {
Expand Down
5 changes: 3 additions & 2 deletions wrappers/resource.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"use strict";
const wrapAsAsync = require("./wrapAsAsync");
let config = require("../leoConfigure.js");
module.exports = function (configOverride, botHandler) {
if (!botHandler) {
botHandler = configOverride;
configOverride = {};
}
Object.assign(config, configOverride);
return function (event, context, callback) {
return wrapAsAsync(function (event, context, callback) {
context.callbackWaitsForEmptyEventLoop = false;
if (context.identity) { // Called Directly not via Api Gateway
event = {
Expand Down Expand Up @@ -120,5 +121,5 @@ module.exports = function (configOverride, botHandler) {
}
});
}
};
});
};
5 changes: 3 additions & 2 deletions wrappers/test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";

const wrapAsAsync = require("./wrapAsAsync");

let cachedHandler;
module.exports = function(configOverride, botHandler) {
Expand Down Expand Up @@ -47,7 +48,7 @@ module.exports = function(configOverride, botHandler) {
}

Object.assign(config, configOverride);
return function(event, context, callback) {
return wrapAsAsync(function(event, context, callback) {
let cb = callback;
callback = (err, data) => {
assert.print();
Expand Down Expand Up @@ -97,5 +98,5 @@ module.exports = function(configOverride, botHandler) {
}


};
});
};
20 changes: 20 additions & 0 deletions wrappers/wrapAsAsync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"use strict";

/**
* Converts a callback-style Lambda handler into an async handler that returns a Promise.
* Newer Node.js Lambda runtimes (nodejs20.x+) no longer support the callback pattern,
* so all exported handlers must be async.
*
* @param {function(event, context, callback)} handler - A callback-style Lambda handler
* @returns {function(event, context): Promise} An async Lambda handler
*/
module.exports = function wrapAsAsync(handler) {
return async function(event, context) {
return new Promise((resolve, reject) => {
handler(event, context, function(err, result) {
if (err) reject(err);
else resolve(result);
});
});
};
};
Loading