1

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?

1
  • 3
    Do you perhaps need to use context.fail()? (Scroll down past the accepted answer and read the others.) Commented Feb 6, 2017 at 12:36

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.