AWS Lambda和API网关响应集成问题 [英] AWS Lambda and API Gateway response integration issue

查看:180
本文介绍了AWS Lambda和API网关响应集成问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经部署了具有Lambda函数和API网关的AWS堆栈.部署后,我独立测试了Lambda函数,它可以正常工作,但是当我使用AWS API Gateway调用它时,它失败并显示`

I have deployed AWS stack with a Lambda function and an API gateway. After deployment I tested Lambda function independently and it works fine but when I invoke it using AWS API Gateway, it fails with `

内部错误:502

Internal Error: 502

我看着cloudwatch日志,上面写着

I looked at cloudwatch logs and it says

转换前的端点响应主体:null

Endpoint response body before transformations: null

我通过以下方式从 Lambda(Python 3.6)返回我的回复-

I am returning my response from Lambda (Python 3.6) in following way -

body = {
        "message": "Success!!"
    }

response = {
    "statusCode": 200,
    "headers": {
        "content-type": "application/json"
    },
    "body": json.dumps(body),
    "isBase64Encoded": False,
}
return response

推荐答案

好的,我发现了问题.实际上,代码是正确的.我进行了一些更改,并将以上代码带到了处理程序之外.因此,我的处理程序正在调用此新函数,并且正在将响应返回到处理程序,但是我错过了再次将接收到的响应从处理程序返回到API网关.

Ok, I found the problem. Actually the code is correct. I made few changes and took the above code outside handler. So my handler was calling this new function and it was returning response to handler but I missed to return the received response again from handler to API gateway.

这篇关于AWS Lambda和API网关响应集成问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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