callback(null,response) inside .then() block of a promise. It works fine when i am using serverless offline but its giving error when using serverless.There are two scenarios:
serverless deploy and when using 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)
}
sls offline but gives internal server error with serverless deploymodule.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)
})
}
There is some problem with the callback(null,response) inside the .then() block of the promise
Setting context.callbackWaitsForEmptyEventLoop = false; solves the problem.