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
preguntada hace un año394 visualizaciones
2 Respuestas
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"?

EXPERTO
respondido hace un año
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
respondido hace 9 meses

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas