0
我有基於Sequelize的代碼在Node.js項目中運行良好。我將該代碼移入AWS Lambda處理程序,並使用節點lambda模塊對其進行測試。現在Sequelize代碼似乎被跳過了。我不確定是否在Lambda完成之前沒有處理這個承諾,或者如果我錯過了其他的東西。以下代碼跳過了「during」console.log,如下面的輸出所示。續集代碼不在AWS內部執行Lambda
var models = require('./models');
exports.handler = function(event, context, callback) {
console.log("Before");
var body = JSON.parse(event.body);
// Find the device ID from the devices table
models.Device.findOne({where: {device_uuid: body.device_uuid}, attributes: ['id']}).then(function(device) {
console.log("During");
// Make sure that we got a device back
if (device === null) {
console.log("Device not found - could not insert data");
return;
}
else {
console.log("Device found, inserting data - " + body.device_uuid);
//Insert the data for this device
models.Data.create({
device_id: device.id,
data: body.data
});
}
});
console.log("After");
callback(null, "{\"status\": \"success\"}");
}
產量...
Before
After
Success:
"{\"status\": \"success\"}"
上我要去哪裏不對任何想法?我使用Node v5.9.0。
我發現如果我刪除了Sequelize代碼運行良好的回調引用。 – user2174937