从AWS Lambda设置HTTP响应标头 [英] Setting http response header from AWS lambda

查看:259
本文介绍了从AWS Lambda设置HTTP响应标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的API网关/Lambda安装程序返回一个HTTP响应标头: Lambda使用回调函数将值作为JSON的一部分返回 然后 Integration Response 将其映射到HTTP标头(使用integration.response.body)

My API Gateway/Lambda setup returns an HTTP response header: Lambda uses callback function to return the value as part of a JSON and the Integration Response maps it into a HTTP header (using integration.response.body)

通过这种解决方案,这些值会在正文和标头中发送回去.

With this solution, the values are sent back both in the body and the header.

如何在不复制响应正文中的值的情况下映射Lambda响应中的标头?

How can I map headers from the Lambda response without duplicating the values in the response body?

推荐答案

如果启用了 Lambda代理集成,则可以将响应标头设置为Lambda输出的一部分,API Gateway会将其返回为对客户端的HTTP响应的一部分.

If you have Lambda proxy integration enabled, you can set the response headers as part of Lambda output and API Gateway will return them as part of the HTTP response to the client.

Node.js示例:

Node.js example:

callback(null, {
    "isBase64Encoded": false, // Set to `true` for binary support.
    "statusCode": 200,
    "headers": {
        "header1Name": "header1Value",
        "header2Name": "header2Value",
    },
    "body": "...",
});

其中headers可以为 null 或未指定,如果不返回额外的响应标头.

where headers can be null or unspecified if no extra response headers are to be returned.

请参见 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆