Node.js 프로젝트에서 잘 실행되는 Sequelize 기반 코드가 있습니다. 그 코드를 AWS Lambda 핸들러로 옮기고 node-lambda 모듈로 테스트하고 있습니다. 이제 Sequelize 코드는 건너 뛴 것처럼 보입니다. 람다가 끝나기 전에 약속이 처리되지 않는지, 아니면 내가 다른 것을 놓치고 있는지 확실하지 않습니다. 다음 코드는 아래 출력에 표시된대로 "during"console.log를 건너 뜁니다.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\"}"
어떤 아이디어? Node v5.9.0을 사용하고 있습니다.
콜백 참조를 제거하면 Sequelize 코드가 정상적으로 실행되는 것으로 나타났습니다. – user2174937