I am writing a simple lambda code to insert some values to mysql table (rds) but i have no clue why it is not working. After reperted tries sometimes it works and subsequent tries again stop working
everytime it fails (does not insert to table) i get the below response
Response:
null
Request ID:
"6814c4b8-65c5-4401-b7c1-ae06426f186c"
Function Logs:
START RequestId: 6814c4b8-65c5-4401-b7c1-ae06426f186c Version: $LATEST
END RequestId: 6814c4b8-65c5-4401-b7c1-ae06426f186c
REPORT RequestId: 6814c4b8-65c5-4401-b7c1-ae06426f186c Duration: 317.80 ms Billed Duration: 400 ms Memory Size: 128 MB Max Memory Used: 75 MB
My Code to insert data or query data is as simple as
const mysql = require('mysql');
const con = mysql.createConnection({
host : process.env.RDS_HOSTNAME,
user : process.env.RDS_USERNAME,
password : process.env.RDS_PASSWORD,
port : process.env.RDS_PORT,
database : process.env.RDS_DATABASE
});
exports.handler = (event, context, callback) => {
// allows for using callbacks as finish/error-handlers
context.callbackWaitsForEmptyEventLoop = false;
const sql = "INSERT INTO MESSAGE (message) VALUES ('I am MySQL')";
con.query(sql, (err, res) => {
if (err) {
throw err
}
callback(null, '1 records inserted.');
})
};
I have double checked the security group settings and it seems to be correct
I have been referring to
``
Any pointers as to what is wrong or what should i check ?
P.S: In a day after 100 attempts i have managed to insert 3 rows with the same code and settings.