I am trying to query MySQL RDS from Lambda using Node js mysql client. The same code works normally in local.
var mysql = require('mysql');
// TODO Read credentials from Secret Manager.
var connection = mysql.createConnection({
host: "XXX",
user: "XXX",
password: "XXX",
database: "XXX",
timezone: 'utc'
});
connection.connect();
exports.handler = async (event, context, callback) => {
connection.query('show tables', function (error, results, fields) {
if (error) {
connection.destroy();
throw error;
} else {
// connected!
console.log(results);
callback(error, results);
connection.end(function (err) { callback(err, results); });
}
});
};
When I execute lambda I neither get error nor results
- Both RDS and Lambda are on same VPC
- Increased Lambda timeout to 5 minutes
- Gave the below permissions to Lambda role
AWSLambdaExecute
AWSLambdaBasicExecutionRole
AWSLambdaVPCAccessExecutionRole
AWSLambda_FullAccess
- Modified RDS security group to allow lambda.