简体   繁体   English

AWS Lambda和API Gateway响应集成问题

[英]AWS Lambda and API Gateway response integration issue

I have deployed AWS stack with a Lambda function and an API gateway. 我已经部署了带有Lambda函数和API网关的AWS堆栈。 After deployment I tested Lambda function independently and it works fine but when I invoke it using AWS API Gateway, it fails with ` 部署后,我独立测试了Lambda函数,它可以正常工作,但是当我使用AWS API Gateway调用它时,它会失败并显示`

Internal Error: 502 内部错误:502

I looked at cloudwatch logs and it says 我看了看云日志,上面写着

Endpoint response body before transformations: null 转换前的端点响应主体:null

I am returning my response from Lambda (Python 3.6) in following way - 我通过以下方式从Lambda(Python 3.6)返回我的响应-

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

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

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. 所以我的处理程序正在调用此新函数,并且正在将响应返回到处理程序,但是我错过了再次将接收到的响应从处理程序返回到API网关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM