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 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南