node.js - AWS Lambda function never calls the callback -
i've created node lambda function simple call aurora database. when test function in console, query returns, can see results in log, callback never seems called , lambda function times out. can't figure out problem is. here can point me problem.
var mysql = require("mysql"); module.exports.handler = function(event, context, cb) { console.log('start\n'); var con = mysql.createconnection({ ... }); console.log('call data\n'); con.query('select * tags', function(err, rows) { console.log('data received db:\n'); console.log(rows); console.log('calling callback'); cb(null, 'success'); console.log('callback called'); }); console.log('data called\n'); };
the resulting cloudwatch log follows...
2016-07-25t14:20:05.343z daf5cd6b-5272-11e6-9036-e73ad17006df start 2016-07-25t14:20:05.398z daf5cd6b-5272-11e6-9036-e73ad17006df call data 2016-07-25t14:20:05.405z daf5cd6b-5272-11e6-9036-e73ad17006df data called 2016-07-25t14:20:05.440z daf5cd6b-5272-11e6-9036-e73ad17006df data received db: 2016-07-25t14:20:05.440z daf5cd6b-5272-11e6-9036-e73ad17006df [ rowdatapacket { id: 1, externalid: 'a87ead34de7e', orgid: 1, name: 'lacinia sapien', createddate: 1448598369, modifieddate: 0 }, ..., rowdatapacket { id: 50, externalid: '9ebaaab372e3', orgid: 1, name: 'et commodo', createddate: 1451551837, modifieddate: 0 } ] 2016-07-25t14:20:05.483z daf5cd6b-5272-11e6-9036-e73ad17006df calling callback 2016-07-25t14:20:05.483z daf5cd6b-5272-11e6-9036-e73ad17006df callback called end requestid: daf5cd6b-5272-11e6-9036-e73ad17006df report requestid: daf5cd6b-5272-11e6-9036-e73ad17006df duration: 300000.12 ms billed duration: 300000 ms memory size: 1024 mb max memory used: 52 mb 2016-07-25t14:25:05.341z daf5cd6b-5272-11e6-9036-e73ad17006df task timed out after 300.00 seconds
thanks question...
lambda timing out after calling callback
i found problem. node mysql module keeps connection open until server closes unless explicitly closed handler logic.
so node event loop never empties , never returns callback. in above code, did ...
con.end();
before calling callback , worked.
Comments
Post a Comment