我一直在努力解决 alb 2 lambda 502 bad gateway 错误。在我的 ALB 访问日志中,它显示了一个“LambdaInvalidResponse”,我猜这是因为我的 lambda 返回了一个无效响应。这应该很容易解决,但我一生都无法弄清楚。有人可以帮忙:)。
在我的 python 代码中,我返回以下内容:
new_response = { "statusCode": 200, "statusDescription": "200 OK", "isBase64Encoded": False, "headers": { "Content-Type": "text/json; charset=utf-8" } }
new_response['body'] = '{"name":"function1"}'
return new_response
但它在 cloudwatch 中是这样的:
返回响应:
{'statusCode': '200', 'body': '{\n "message": "Success",\n "response": {\n "body": "{\"name\":\"function1\ "}",\n "headers": {\n "Content-Type": "text/json; charset=utf-8"\n },\n "isBase64Encoded": false,\n "statusCode": 200, \n "statusDescription": "200 OK"\n }\n}'}
我真的很想知道为什么结果会被包裹在身体里——有人有什么想法吗?