0
votes

I'm trying to invoke a lambda function. The function works when the data is available resolve(), but when there is an error, it does not proceed with the callback, and just gives me an error.

lambda.invoke({
        FunctionName: 'cognitoFunction',
        Payload: JSON.stringify({
            email: slots.Email
        })
    }, function(err, data) {
        if(err) { // Does not work

            callback(close3(sessionAttributes, { "contentType": "PlainText", "content": "ERROR" }));

        }
        else { // This part works
            callback()
        }
    });

"errorType": "DependencyFailedException",

"errorMessage": "Invalid Lambda Response: Received error response from Lambda: Unhandled"

1

1 Answers

0
votes

I figured out the issue. The error goes into 'data', not into 'error' :

lambda.invoke({
        FunctionName: 'functionName',
        Payload: JSON.stringify({
            email: slots.Email
        })
    }, function(error, data) {
        if(error){
            callback(...)
        }
        else {
            data = JSON.parse(data.Payload);
            if(data.errorMessage) { // The error output is in here
                callback(close(sessionAttributes, { "contentType": "PlainText", "content": data.errorMessage }));
            }
        }
    });