Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Lambda "Process exited before completing request"

I am trying to call a DynamoDB client method and get one item from the DynamoDB table. I am using AWS Lambda. However, I keep getting the message:

"Process exited before completing request."

I have increased the timeout just to make sure, but the processing time is less than the timeout. Any advice?

console.log('Loading event');
var AWS = require('aws-sdk');
var dynamodb = new AWS.DynamoDB({apiVersion: '2012-08-10'});

exports.handler = function(event, context) {
dynamodb.listTables(function(err, data) {
});

var params = {
    "TableName": "User",
     "Key":
        {"User Id"   : {"S":event.objectId}
    },
    "AttributesToGet"   : ["First Name","Last Name", "Latitude", "Longitude"],
    "ConsistentRead"    : true
  }


   dynamodb.getItem(params, function(response,result) {
    response.on('data', function(chunk){
    console.log(""+chunk);
    console.log("test1")
    context.done(result);
});
result.on('ready', function(data){
    console.log("test2")
    console.log("Error:" + data.error);
    console.log("ConsumedCapacityUnits:" + data.ConsumedCapacityUnits);
     context.done('Error',data);
    // ...
});
});
};
like image 299
Rupert Avatar asked Jul 25 '15 15:07

Rupert


2 Answers

Take a look at your memory consumption (included in last log line). I got the same message when I assigned too little memory to my lambda function.

like image 172
linqu Avatar answered Oct 20 '22 01:10

linqu


The message "Process exited before completing request" means that the Javascript function exited before calling context.done (or context.succeed, etc.). Usually, this means that there is some error in your code.

I'm not a Javascript expert (at all) so there may be more elegant ways to find the error but my approach has been to put a bunch of console.log messages in my code, run it, and then look at the logs. I can usually zero in on the offending line and, if I look at it long enough, I can usually figure out my mistake.

I see you have some logging already. What are you seeing in the output?

like image 55
garnaat Avatar answered Oct 20 '22 03:10

garnaat