AWS Gateway always returns the default status code

空扰寡人 提交于 2019-12-11 14:31:57

问题


When I test my Lambda through AWS Gateway, I can see this lines being logged:

Wed Jul 19 20:06:11 UTC 2017 : Method response body after transformations: {"errorCode":0,"headers":{},"statusCode":567,"base64Encoded":false}

As you can see I'm returning 567 as status Code. But I always see 200:

Then, this is my configuration in Integration Response:

I'm using as reg exp .*"statusCode":567.*, but it is not matching with {"errorCode":0,"headers":{},"statusCode":567,"base64Encoded":false}.

These are my http status codes in Method Responses section:

I can not make return other than 200. I tried changing the default to be 567 instead of 200. That way it returns 567. So looks like my setting makes my API to return always the default response.

Does anybody have a clue of what I'm doing wrong?


回答1:


Try using lambda-proxy instead of lambda-integration.

This way, you construct your response in your lambda function and not in the API Gateway templates.

In my opinion, it's easier to manipulate the response in code rather than using API Gateway templates.




回答2:


In this case, I think it is your regex that is at fault: .*"statusCode":567.*

It's matching on the internal JSON message, so it would need changed to .*\"statusCode\":567.* to match - this worked in my case anyway

I used this answer for mine, slightly simpler that what you are looking for.



来源:https://stackoverflow.com/questions/45200322/aws-gateway-always-returns-the-default-status-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!