如何在 AWS API 网关中允许响应 headers?

How to allow response headers in AWS API Gateway?

REST API 部署在 returns JSON 响应的 AWS EC2 上,并且部署在 API 网关上。

此 API returns 来自 AWS EC2 的响应 header,状态代码为 200,但 API 网关未将其传回客户端。

你知道怎么解决吗?

响应 headers 需要根据您在 API 网关中设置的集成类型明确定义和映射。

如果您只想将所有内容从 EC2 中继回客户端并且不希望发生任何转换,那么根据您使用的集成类型(http、vpclink)只需勾选“使用代理 Integration/Use HTTP 代理集成”资源 => 方法 => 集成请求下的框。

aws doc 说,

For a proxy integration, API Gateway automatically passes the backend output to the client as an HTTP response. You do not set either an integration response or a method response

对于非代理集成,您需要同时设置集成响应和方法响应