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
已提问 4 年前1483 查看次数
1 回答
0
已接受的回答

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
专家
Uri
已回答 4 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则