我已经部署了具有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网关响应集成问题
发布评论