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?

1 réponse
0
Réponse acceptée

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
EXPERT
Uri
répondu il y a 4 ans

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions