Lambda Serverless Nodejs - 在承诺中调用回调时获取 "Internal server error"

Lambda Serverless Nodejs - Getting "Internal server error" when callback is called inside a promise

我正在尝试调用 .then() 块内的 callback(null,response) 承诺。当我使用 serverless offline but its giving error when using serverless.

时它工作正常

有两种情况:

1 工作正常(使用 serverless deploy 部署时和使用 sls offline start 时)

module.exports.getAssembly = (event, context, callback) => {

        const response = {
            statusCode: 200,
            body: JSON.stringify({
                message: 'Go Serverless v1.0! Your function executed successfully!'
            }),
        };
        callback(null, response)


}

2 与 sls offline 一起工作正常,但 internal server errorserverless deploy

module.exports.getAssembly = (event, context, callback) => {


    mysql.query('SELECT * from assemblies',connection).then((returnedObject)=>{
        const response = {
            statusCode: 200,
            body: JSON.stringify({
                message: returnedObject.results
            }),
        };
        callback(null, response)

    })

}

promise

.then() 块中的 callback(null,response) 有问题

设置context.callbackWaitsForEmptyEventLoop = false;解决问题。