Sequelize.js 未在AWS Lambda内执行Sequelize代码

Sequelize.js 未在AWS Lambda内执行Sequelize代码,sequelize.js,Sequelize.js,我有基于Sequelize的代码,在Node.js项目中运行良好。我将该代码移动到AWS Lambda处理程序中,并使用节点Lambda模块对其进行测试。现在似乎跳过了Sequelize代码。我不确定在Lambda完成之前承诺是否没有得到处理,或者我是否错过了其他东西。下面的代码跳过“在”console.log,如下面的输出所示 var models = require('./models'); exports.handler = function( event, context, call

我有基于Sequelize的代码,在Node.js项目中运行良好。我将该代码移动到AWS Lambda处理程序中,并使用节点Lambda模块对其进行测试。现在似乎跳过了Sequelize代码。我不确定在Lambda完成之前承诺是否没有得到处理,或者我是否错过了其他东西。下面的代码跳过“在”console.log,如下面的输出所示

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。

我刚开始使用apigateway/lambda和sequelize,但据我所知,Node和sequelize的回调应该在“then”块中

昨天发现,如果您使用的是回调(null,successData),那么性能非常差(在选择的前1项中大于11秒)。必须更改标志context.callbackhaitsforemptyeventloop=false,现在api调用需要24毫秒

    //Important to improve performance! 
    context.callbackWaitsForEmptyEventLoop = false

    // 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) {
            callback(new Error("Device not found - could not insert data"))
        }
        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
            })
            .then(function(insertedData){
               callback(null, insertedData.toJSON())     
            })
            .catch(function(error){ 
                callback( new Error("Error creating")
            })
        }
    })    
    console.log("After")
}

我刚开始使用apigateway/lambda和sequelize,但据我所知,node和sequelize的回调应该在“then”块中

昨天发现,如果您使用的是回调(null,successData),那么性能非常差(在选择的前1项中大于11秒)。必须更改标志context.callbackhaitsforemptyeventloop=false,现在api调用需要24毫秒

    //Important to improve performance! 
    context.callbackWaitsForEmptyEventLoop = false

    // 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) {
            callback(new Error("Device not found - could not insert data"))
        }
        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
            })
            .then(function(insertedData){
               callback(null, insertedData.toJSON())     
            })
            .catch(function(error){ 
                callback( new Error("Error creating")
            })
        }
    })    
    console.log("After")
}

我发现如果删除回调引用,Sequelize代码运行良好。我发现如果删除回调引用,Sequelize代码运行良好。