首页 文章

AWS Gateway始终返回默认状态代码

提问于
浏览
0

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

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

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

enter image description here

然后,这是我在Integration Response中的配置:

enter image description here

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

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

enter image description here

除了200之外我无法返回 . 我尝试将默认值更改为567而不是200.这样它返回567.所以看起来我的设置使我的API返回 always 默认响应 .

有没有人知道我做错了什么?

2 回答

  • 1

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

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

    在我看来,在代码中操作响应比使用API网关模板更容易 .

  • 1

    在这种情况下,我认为这是你的正则表达式错误: .*"statusCode":567.*

    它匹配内部JSON消息,因此需要更改为 .*\"statusCode\":567.* 才能匹配 - 无论如何这都适用于我的情况

    我使用了this answer,比你想要的更简单一些 .

相关问题