I've been grappling with alb 2 lambda 502 bad gateway errors. In my ALB access logs, it shows a 'LambdaInvalidResponse' which i'm guessing is because my lambda returns an invalid response. This should be easily fixed but i can't for the life of me figure it out. Can someone help :).
In my python code i'm returning the following:
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
But it comes out like this in cloudwatch:
Returning response:
{'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}'}
I'd really like to know why the result is getting wrapped up in the body - anyone got any ideas?