Node.jsプロジェクトでうまく動作するSequelizeベースのコードがあります。私はそのコードをAWS Lambdaハンドラに移し、node-lambdaモジュールでテストしています。今Sequelizeコードはスキップされているようです。ラムダが終わる前に約束が処理されていないのか、何か他のものが欠けているのかどうかは分かりません。次のコードは、以下の出力に示すように、console.logの "during"をスキップします。AWSラムダ内でコードが実行されないようにする
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\"}"
任意のアイデア?私はノードv5.9.0を使用しています。
私は、Sequelizeコードがうまく動作するコールバック参照を削除すると、わかりました。 – user2174937