I have tried all the solutions found on other similar stack overflow questions but I still get this error. I'm a beginner and have only just started learning this. So, I'm not sure if I'm following the solutions right. But here's my code. I would appreciate it if someone could help me.
var mysql = require('mysql');
var pool = mysql.createPool({
host : 'host',
user : 'user',
password : 'password',
database : 'student',
connectionLimit : 10,
multipleStatements : true
});
exports.handler = function(event, context, callback) {
context.callbackWaitsForEmptyEventLoop = false;
pool.getConnection(function(err, connection) {
connection.query("SELECT name FROM 'student'.'course'", function (err, results, fields) {
if (err) {
console.log("NOT-CONNECTED!");
connection.destroy();
throw err;
} else {
// connected!
console.log("CONNECTED!");
console.log(results);
callback(err, results);
connection.end(function (err) { callback(err, results);});
}
});
});
};
context.done(orcontext.succeed,callbacketc.). You can try increase function's timeout (default is 6s), I think thegetConnectionfunction takes more time, you can addconsole.logstep by step to detect the issue. - hoangdv