AWS Lambda "Process exited before completing request"

Amazon Web-ServicesAws Lambda

Amazon Web-Services Problem Overview


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);
    // ...
});
});
};

Amazon Web-Services Solutions


Solution 1 - Amazon Web-Services

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.

Solution 2 - Amazon Web-Services

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?

Solution 3 - Amazon Web-Services

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."

Solution 4 - Amazon Web-Services

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.

Solution 5 - Amazon Web-Services

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
}

Solution 6 - Amazon Web-Services

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRupertView Question on Stackoverflow
Solution 1 - Amazon Web-ServiceslinquView Answer on Stackoverflow
Solution 2 - Amazon Web-ServicesgarnaatView Answer on Stackoverflow
Solution 3 - Amazon Web-ServicesManohar Reddy PoreddyView Answer on Stackoverflow
Solution 4 - Amazon Web-ServicesJoseph Bolade Caxton-IdowuView Answer on Stackoverflow
Solution 5 - Amazon Web-ServicesShubham DhaneraView Answer on Stackoverflow
Solution 6 - Amazon Web-ServicesNitendra Singh YadavView Answer on Stackoverflow