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

EXPERTE
beantwortet vor einem Jahr
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
beantwortet vor 9 Monaten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen