Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (12.8k points)

I have written a simple lambda function in nodejs which queries data from amazon rds.(note : my lambda and rds are in default vpc with all ports open and also tried increasing time out in lambda)

My issue is when I test my lambda function I get log output with the queried data but I am also getting

Execution result: failed with "errorMessage": "2017-07-05T15:05:27.425Z 596fdf39-6193-11e7-9176-f58796899f9b Task timed out after 3.00 seconds" }

var mysql = require('mysql');

exports.handler = (event, context) => {

var con = mysql.createConnection({

  host: "testdb.cxyzu.ap-south-1.rds.amazonaws.com",

  user: "root",

  password: "mypassword",

  database: "test",

  port: "3306",

 // debug: true

});

con.connect(function(err) {

  if (err) throw err;

  console.log("Connected!");

 // var sql = "INSERT INTO users (id, name) VALUES (4, 'dfdd')";

var sql = "select * from test.users";

  con.query(sql, function (err, result) {

    if (err) throw err;

//    console.log("1 record inserted");

      console.log(result);

  });

});

//callback("sucess");

}

1 Answer

0 votes
by (29.8k points)

You need to exit the lambda through a success or error callback. Otherwise, the engine stays on until a timeout occurs.

One way to exit your lambda would be to call 'context.succeed("done");' after you code is done.

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.7k users

Browse Categories

...