I'm making Lambdas with node js and mysql connection to an RDS, the thing is the first time I trigger the Lambda function I get the error "Process exited before completing request", then it works fine.
Here is my code:
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);
})
};
Any idea of what is causing it?