AWS Gateway始终返回默认状态代码 [英] AWS Gateway always returns the default status code

查看:123
本文介绍了AWS Gateway始终返回默认状态代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我通过AWS Gateway测试Lambda时,可以看到以下行被记录:

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}

如您所见,我将返回567作为状态码.但我总是看到200:

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

然后,这是我在集成响应"中的配置:

Then, this is my configuration in Integration Response:

我正在使用reg exp .*"statusCode":567.* ,但它与 {"errorCode":0,"headers":{},不匹配, "statusCode":567,"base64Encoded":false} .

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

这些是我在方法响应"部分中的http状态代码:

These are my http status codes in Method Responses section:

我无法返回200以外的其他值.我尝试将默认值更改为567而不是200.这样它就返回了567.因此,看来我的设置使我的API始终返回了始终响应.

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?

推荐答案

尝试使用lambda-proxy而不是lambda-integration.

Try using lambda-proxy instead of lambda-integration.

这样,您可以在lambda函数中而不是在API Gateway模板中构建响应.

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

我认为,用代码处理响应比使用API​​ Gateway模板要容易得多.

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

这篇关于AWS Gateway始终返回默认状态代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆