1
votes

I have created a simple lambda function having following code.

exports.handler = (event, context, callback) => {
    const operation = event.body.operation;
    console.log("operation = ", operation)
    switch (operation) {
        case 'add': callback(null, 'post method');
            break;
        case 'add1': callback(null, {
            status: 0,
            errorType: "InternalServerError",
            errorCode: "001",
            errorMessage: "post method error."
        }
        );
        default: callback(null, 'Hello from Lambda');
            break;
    }
};

It will be connected with Amazon API Gateway. Using a REST client able to get success & error responses. But HTTP status code is still 200. Then I have modified API Gateway integration responses in two ways.

 1. Selection pattern : “InternalServerError”
 2. Selection pattern : “.*InternalServerError”
    Method response : 500

But I still got 200 HTTP status code. What is the actual issue related with this selection patterns?

2
Do you perhaps need to use context.fail()? (Scroll down past the accepted answer and read the others.)Michael - sqlbot

2 Answers

1
votes

API Gateway checks for the error pattern when the error is thrown from Lambda function using context.fail(). Refer to this article for more details on handling Lambda error in API GW.

0
votes

In your case you need to return a proper HTTP response, from my answer here: