Mapping Lambda output to Gateway API gives server error

I have an AWS API Gateway installation served by the Python Lambda function. For successful responses, Lambda returns a form response:

"200:{\"somekey\": \"somevalue\"}" 

By default, the integration response settings in the gateway console use only one rule configured using the Lambda Error Regex of. * matching with answer to 200. This works fine.

The problem is that I am trying to change this value to 200. * (in order to include more specific codes in the future). Now i get

 {"message": "Internal server error"} 

every time I hit the gateway with any request (the result is 200 or not).

CloudWatch does not record error logs.

enter image description here

I want to know how I can successfully convert Lambda outputs to HTTP status codes in the AWS API Gateway.

+6
source share
2 answers

If you are running a test run in the API gateway, an error similar to this should appear in the test run log:

Sat Nov 21 07:41:25 UTC 2015: Execution failed due to configuration error: No match for output display and output display configured by default

The problem is that there is no longer a default mapping to get a successful response. The goal of a regular error expression is to catch errors and correlate them with status codes. A regular expression of errors looks for the errorMessage property of a failed json response. If you set status code 400 to the default value (empty), you will find your successful answer, always matching status code 400.

It is best to leave 200 as a standard (empty) regular expression. Then set specific regex values ​​to check for different error messages. For example, you can have several regular error code status codes and a common common symptom to get the 500th.

enter image description here

+10
source

For those who tried everything, asked this question and were unable to do this work (for example, I), check out thedevkit comment on this post (saved my day):

https://forums.aws.amazon.com/thread.jspa?threadID=192918

Reproducing it completely below:

I had problems with this myself, and I believe that the new line of characters are the culprits.

foo. * will match the occurrences of "foo" followed by any characters EXCLUDING a new line. This is usually solved by adding the "/ s" flag, i.e. "foo. * / s", but the regular expression Lambda error does not look like this.

Alternatively, you can use something like: foo (. | \ N) *

+2
source

All Articles