在Lambda函数中超过了最大调用堆栈

时间:2016-06-11 04:29:03

标签: node.js amazon-web-services lambda

我有一个nodejs lambda函数,它基本上在newman(Postman的JS库)中运行一组测试。测试成功运行但是当lambda尝试使用codepipeline.putJobSuccessResult向Codepipeline发回消息时,它会不断抛出超出最大调用堆栈的错误。打印的错误堆栈看起来不是很长(我只能看到6行打印)。

有关堆栈跟踪超出原因以及如何轻松调试的任何帮助都会有所帮助。

相关的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);
}

由于

1 个答案:

答案 0 :(得分:-1)

context没有successfail方法。使用callback参数。

试试这个:

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