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)

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"?

전문가
답변함 일 년 전
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달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠