64

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);
    // ...
});
});
};
coffee-grinder
  • 26,940
  • 19
  • 56
  • 82
Rupert
  • 4,209
  • 7
  • 31
  • 36
  • Here are some dynamo db examples I made if anyone's looking for some template code https://github.com/deacons2016/DynamoDb-Lambda-Examples – Rupert Oct 31 '15 at 17:47
  • I would recommend making a separate test node.js file locally and run your functionality. Once you verify deploy the payload. – Hexy Nov 15 '16 at 18:03

6 Answers6

69

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.

linqu
  • 11,320
  • 8
  • 55
  • 67
  • 3
    Although the top answer was technically right, increasing my memory consumption allowed me to debug the error in cloudwatch. With the previous memory level, the function would end before hitting a stackoverflow and cloud watch would provide no help. After increasing the memory, I was finally able to discover my finely crafted infinite loop. :D – Govind Rai Aug 13 '18 at 03:59
55

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?

garnaat
  • 44,310
  • 7
  • 123
  • 103
  • you can also use an online javaScript Lint to help you figure out the mistake: http://www.javascriptlint.com/online_lint.php – Gal Rom Feb 16 '16 at 20:28
  • 4
    thanks it was very helpful, just instead of using `console.log`, or in addition, you can consult the logs in cloudwatch, errors are displayed there it can save lot of time – Cinn Jul 14 '16 at 14:48
6

I have used callback, instead of context.
More recent examples on aws website use callback instead of context.

To complete request, either of the below must be called:

callback(error);         // This is used when there is an error
// or
callback(null, data);    // This is used when there is a success
                         // 'data' will contain success result, like some JSON object  

When lambda execution completes the request,
failing to call one of the above callbacks,
you will see below error:

"Process exited before completing request."

Manohar Reddy Poreddy
  • 25,399
  • 9
  • 157
  • 140
1

Error in your code. Remove the last }); and don't use context it is there for backward compatibility, use callbacks on node.js 4.3 and 6.1 runtime.

1

Maybe you are not following aws lamda standard of using the function check this Golang code.

package main
import "github.com/aws/aws-lambda-go/lambda"

func main() {
   lambda.Start(yourFunction)
}

func yourFunction(){
   // do your stuff
}
1

Check your lamda memory usage, for me this error was occurred because of lambda was using 201 MB memory, which was greater than allowed 200 MB of memory for its execution.

First verify your code and if it is ok, increase memory allotment to this lambda from configuration > General Configuration > Edit > Increase memory