AWS Lambda和API网关响应集成问题

编程入门 行业动态 更新时间:2024-10-23 01:30:41
本文介绍了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网关响应集成问题

本文发布于:2023-11-24 04:26:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1623962.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:网关   AWS   Lambda   API

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!