Load balancer returns HTTP 502 when targeting lambda

0

Hello aws community,

I have an issue with a lambda in which I ended up returning the hardcoded response like shown below ... response = { "statusCode": 200, "statusDescription": "200 OK", "isBase64Encoded": false, "headers": { "Content-Type": "text/html" }, "body": "<p>Test string returned from Lambda</p>" } return response;

I have played around with headers and content-types ... Nothing seems to resolve the issue.

When checking the ELB logs I see ... https 2023-01-24T20:04:03.214570Z app//******* xxx.xxx.xxx.xxx:xxxxx - 0.008 0.538 0.000 502 - 1629 277 "GET https://*************************************:443/************* HTTP/1.1" "PostmanRuntime/7.29.2" ECDHE-RSA-AES128-GCM-SHA256 TLSv1.2 arn:aws:elasticloadbalancing:**************************************** "Root=" "***********************************" "arn:aws:acm::certificate/***************************" 0 2023-01-24T20:04:02.667000Z "forward" "-" "LambdaInvalidResponse" "-" "-" "-" "-"

Does anyone have any ideas on how I could further troubleshoot this issue? Is there maybe a way to verify what the load balancer is receiving as a response from the lambda? I have tried logging what the lambda is returning. To me it seems correct and in line with what I find in forums that address similar topic.

Greetings,

Hamid K.

  • What language is that you're using?

  • I am using nodejs (javascript)

Hamid
已提问 1 年前394 查看次数
2 回答
0

That looks fine to me unless you've enabled multi-value headers in which case the response structure is different. Can you provide more information such as logging output from your Lambda containing the request and the response logged just before "return response"?

专家
已回答 1 年前
0

So, I just had this issue, and since an AWS engineer helped me resolve it, I figure I post the answer here too.

All your headers have to have a string value. Returning a number, or something other than a string in the header, guarantees you a 502 and InvalidResponseError. I don't think this is mentioned anywhere in the AWS documentation.

Aeolun
已回答 9 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则