I'm trying to connect to a msql database on AWS using the following lambda function
const dotenv = require('dotenv');
dotenv.config();
var mysql = require('mysql');
var pool = mysql.createPool({
host : process.env.DBHOST,
user : process.env.DBUSER,
password : process.env.DBPASSWORD,
database : process.env.DBNAME
});
exports.handler = (event, context, callback) => {
//prevent timeout from waiting event loop
context.callbackWaitsForEmptyEventLoop = false;
pool.getConnection(function(err, connection) {
// Use the connection
connection.query('select * from products', function (error, results, fields) {
// And done with the connection.
connection.release();
// Handle error after the release.
if (error) callback(error);
else callback(null,results[0].emp_name);
});
});
};
When executed it gives the following error:
Response:
{
"errorMessage": "2020-12-05T16:51:55.273Z 281776f1-ee7f-4c8c-8862-a7371d1a8f37 Task timed out after 3.00 seconds"
}
Request ID: "281776f1-ee7f-4c8c-8862-a7371d1a8f37"
Function logs:
START RequestId: 281776f1-ee7f-4c8c-8862-a7371d1a8f37 Version: $LATEST
END RequestId: 281776f1-ee7f-4c8c-8862-a7371d1a8f37
REPORT RequestId: 281776f1-ee7f-4c8c-8862-a7371d1a8f37 Duration: 3003.58 ms Billed Duration: 3000 ms Memory Size: 128 MB Max Memory Used: 75 MB Init Duration: 202.41 ms
2020-12-05T16:51:55.273Z 281776f1-ee7f-4c8c-8862-a7371d1a8f37 Task timed out after 3.00 seconds
How do I fix this?