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?

Rodia
  • 1,407
  • 8
  • 22
  • 29
Abdul Manaf
  • 4,933
  • 8
  • 51
  • 95
  • 3
    Do you perhaps need to use [`context.fail()`](http://stackoverflow.com/q/31329495/1695906)? (Scroll down past the accepted answer and read the others.) – Michael - sqlbot Feb 06 '17 at 12:36

2 Answers2

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.

Balaji
  • 1,028
  • 8
  • 12
0

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

Mrk Fldig
  • 4,244
  • 5
  • 33
  • 64