0

I have a nodejs lambda function which essentially runs a set of tests in newman (A JS library of Postman). The tests run successfully but when the lambda is trying to send back a message to Codepipeline using codepipeline.putJobSuccessResult, it keeps throwing the maximum call stack exceeded error. The printed error stack doesn't seem to be very long (I can just see 6 lines printed).

Any help with how why the stack trace is exceeding and how it could be debugged easily would help.

Relevant exports.handler

exports.handler = function(event, context) {
    var jobId = event["CodePipeline.job"].id;
    console.log("Triggering tests for job "+ jobId);


    var putJobSuccess = function(message) {
        codepipeline.putJobSuccessResult({jobId: jobId}, (err, data) => {
            if (err) {
                context.fail(err);
            } else {
                context.succeed(message)
            }
        });
    }

    var putJobFailure = function(message) {
        console.log("Tests failed for job: " + jobId);
        var params = {
            jobId: jobId,
            failureDetails: {
                message: JSON.stringify(message),
                type: 'JobFailed',
              externalExecutionId: ""
            }
        }
    }

    var testRunnerCallback = function(response) {
        if (response === 1) {
            putJobFailure("Tests failed. View logs for details");
        } else {
            putJobSuccess("All Tests passed");
        }
    }

    Newman.execute(collections, newmanOptions, testRunnerCallback);
}

Thanks

bythe4mile
  • 642
  • 7
  • 16

1 Answers1

-1

The context has no success or fail method. Use the callback parameter.

Try this:

exports.handler = function(event, context, callback) {
    var jobId = event["CodePipeline.job"].id;
    console.log("Triggering tests for job "+ jobId);


    var putJobSuccess = function(message) {
        codepipeline.putJobSuccessResult({jobId: jobId}, callback);
    }

    var putJobFailure = function(message) {
        console.log("Tests failed for job: " + jobId);
        var params = {
            jobId: jobId,
            failureDetails: {
                message: JSON.stringify(message),
                type: 'JobFailed',
              externalExecutionId: ""
            }
        }
        callback(params);
    }

    var testRunnerCallback = function(response) {
        if (response === 1) {
            putJobFailure("Tests failed. View logs for details");
        } else {
            putJobSuccess("All Tests passed");
        }
    }

    Newman.execute(collections, newmanOptions, testRunnerCallback);
}
eenagy
  • 912
  • 1
  • 8
  • 22
  • The context object *does* have success and fail methods. Not sure where you're getting your information. – idbehold Jun 13 '16 at 13:45
  • Yup it does have the success and fail methods. In either case though the codepipeline.putJobSuccessResult keeps exceeding stack size – bythe4mile Jun 14 '16 at 00:02
  • @idbehold I have checked the [docs](http://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-context.html), and logged out context object by running lambda, what did I miss?? – eenagy Jun 14 '16 at 02:44
  • @eenagy see [their docs here](https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-using-old-runtime.html#nodejs-prog-model-oldruntime-context-methods): "The context object supports the done(), succeed(), and fail() methods that you can use to terminate your Lambda function. **These methods are also present in runtime v4.3 for backward compatibility.**" – idbehold Jun 14 '16 at 17:37