我有一個在節點環境中完美運行的功能。該函數使用promise,S3調用和then和catch使用相關的200/500 statusCode和每個消息體中的消息體呼叫回調。AWS Lambda無需等待承諾即可返回
現在我部署它作爲一個包裝lambda函數圍繞它看起來像這樣:
module.exports.getAvailableDates = (event, context, callback) => {
const lambdaParams = retrieveParametersFromEvent(event);
console.log(`Got the criteria`);
module.exports.getFilteredDates(lambdaParams.startDate,
lambdaParams.endDate, callback);
console.log(`Returning without the internal function results`);
};
內部功能如下:
module.exports.function getFilteredDates(startDate, endDate) {
const dateSet = new Set();
return new Promise((resolve, reject) => {
const getAllDates = (isDone) => {
if (isDone) {
const Dates = Array.from(dateSet).join();
resolve(Dates);
return;
}
getTestedDates(startDate, endDate, region, func, memory,
lastDateKey, dateSet).then(getAllDates).catch((error) => {
reject(error);
});
};
lastDateKey = '';
getTestedDates(startDate, endDate, region, func, memory,
lastDateKey, dateSet).then(getAllDates).catch((error) => {
reject(error);
});
});
}
而且甚至更多的內部函數如下類似,只有它實際上查詢S3數據庫並返回匹配日期標準的密鑰列表。
在AWS CloudWatch日誌中,我看到兩個打印並僅在它們之後顯示內部函數輸出。我的理解是,lambda函數並沒有等待內部函數的承諾實際完成其工作(包括內部等待承諾),並返回給我一個不好的地位。我能做什麼?
ü可以分享你的'promise'代碼 –