我正在使用与RDS的节点js和mysql连接制作Lambda,事情是我第一次触发Lambda函数时遇到错误“在完成请求之前退出流程”,然后它可以正常工作。
这是我的代码:
const mysql = require('mysql');
module.exports.selectAll = (event, context, callback) => {
context.callbackWaitsForEmptyEventLoop = false;
//Response
let response = {
status: 200,
message: '',
data: [],
}
//Body request
const {user} = event
const connection = mysql.createConnection({
host: process.env.host_DB,
user: process.env.user_DB,
password: process.env.password_DB,
database: process.env.database_DB
});
connection.open();
connection.query(`call test_db.getAll('${user != undefined? user : 0}')`,
function(err, results, fields) {
if(err){
console.log(err);
response.status = 500;
response.message = err.message;
response.data = [];
}else{
response.data = results[0];
response.message = 'Success';
}
connection.end();
callback(null, response);
})
};
是什么原因引起的?