Return Count from Lambda into the "Response Header" of the API

0

A customer is using API Gateway to return information via Lambda. However, they would like to put a count from Lambda into the "Response Header" of the API, which is returned to the requester, instead of in the body of the response.

In API Gateway how can I take the response from Lambda and map the "count" field into the header of the HTTP response?

AWS
preguntada hace 4 años1483 visualizaciones
1 Respuesta
0
Respuesta aceptada

If you return the count in a header from the Lambda function you can just reference it using integration.response.header.header-name.

To return a header from the Lambda function just return something like this:

{
    "statusCode": 200,
    "headers": {
        "header1Name": "header1Value",
        "header2Name": "header2Value",
    },
    "body": "...",
}

For more information see here. You will see that it describes that only headers from the backend can be mapped to headers in the response.

profile pictureAWS
EXPERTO
Uri
respondido hace 4 años

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