AWS API 网关代理响应失败/丢弃 [英] AWS API Gateway Proxy Response failure/dropped

查看:34
本文介绍了AWS API 网关代理响应失败/丢弃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:

AWS API Gateway 代理在使用 Postman 时不会从我的后端服务传回响应,但可以在 curl 上工作

AWS API Gateway Proxy is not passing back the response from my backend service when using Postman, but works on curl

描述:

我想通过 AWS API 网关公开一个后端服务.在这种情况下,网关的使用纯粹是作为 HTTP 代理.所以,

I have a backend service that I want to exposed via AWS API gateway. The use of gateway in this case is purely as a HTTP proxy. So,

  1. 创建了一个新的 API
  2. 使用 ANY 将资源设置为代理"
  3. 提供我的后端服务地址
  4. 已部署(无需身份验证,但需要 API 密钥)
  5. 可以从部署阶段 url 成功调用我的后端服务
  6. 使用 CA 证书创建自定义域
  7. 在我的 DNS 提供商上创建别名
  8. 1 小时后域启动并指向云端

问题

我调用了自定义域,

  1. API 网关收到它
  2. 通话记录在 cloudwatch 日志中,并且
  3. 它正在击中我的后端.
  4. 后端回复 API 网关.

但是,在我的邮递员身上,我看到无法得到任何回复"

But, on my postman, I see a "Could not get any response"

但是,如果我通过 curl 尝试此操作,我会得到后端发送的预期响应.所以,不清楚的部分是 -

However, If I try this via curl, I am getting the intended response back that was sent by my backend. So, the unclear part is -

  1. Postman 调用或基于 GET 到我的端点的普通浏览器 URL 栏有什么问题?

  1. What is wrong with Postman call or a normal browser url bar based GET to my endpoint?

为什么 curl 会成功?

Why is curl successful?

而且,对于我的 API 网关端点,我已将 API 密钥设置为必需.我创建了一个 API 密钥并将其分配给 API.有趣的是,即使我没有传递 API 密钥,curl 调用仍然成功.为什么 API Gateway 可以允许这样的调用?

and, for my API Gateway endpoint, I have set API Key as mandatory. I have created an API key and assigned it to the API. Interesting part is that, the curl call is still successful even if I do not pass an API Key. Why could API Gateway allow such calls ?

另一个令我困惑的问题是,我必须在用于 API 版本控制的 AcceptContent-Type 中传递自定义值.

Another confusing issue for me is, I have to pass custom values in the Accept, and Content-Type that I use for my API versioning.

例如:Accept: application/json-v1 失败但 Accept: application/xml-v1 正在工作.

Ex: Accept: application/json-v1 is failing but Accept: application/xml-v1 is working.

我认为这与价值有关,因为 API Gateway 不喜欢它.

I think this is something to do with value as API Gateway is not liking it.

我已经彻底阅读了文档,但仍然找不到对所有这些问题的任何合理解释.我错过了什么导致这些奇怪的问题?到目前为止,我的 google fu 也不足以解决这个问题.

I have read through the docs thoroughly and still could not find any reasonable explanation for all these issues. What am I missing that is causing these weird bag of issues ? My google fu so far too was not enough to solve this.

请帮助或同样指出 AWS 网关中可以帮助解决此问题的特定文档或我可能在这些主题上遗漏的任何讨论主题.

Please help or equally point me to the specific docs in AWS gateway that can help solve this or any discussion threads that I may have missed on these topics.

至少得到其中一个的答案会让我清楚我的方法.

At least getting an answer for one of these will give me a clarity on my approach.

谢谢大家!

推荐答案

快速回答:添加标题 Accept-Encoding:identity

我在使用 AWS api-gateway 时遇到了完全相同的问题.就我而言,解决方案是从邮递员那里添加标头 Accept-Encoding:identity 或配置 AWS API 以默认将其发送到我的后端.

I had the exact same problem when using AWS api-gateway. In my case the solution was to add header Accept-Encoding:identity either from postman or configure the AWS API to send it to my backend by default.

当我直接从邮递员调用我的后端时,我可以将标头设置为 gzip,邮递员将正确显示响应,但是当我通过 AWS 执行时,这似乎是我没有的问题无法解决.将提到的标头设置为 Identity 将指示后端不要修改响应(或应用身份功能).

When I call my backend directly from postman I can set the header to gzip and postman will display the response correctly, but when I do it through AWS it seems to be an issue that I haven't been able to address. Setting the mentioned header to Identity will instruct the backend to don't modify the response (or apply the identity function).

这篇关于AWS API 网关代理响应失败/丢弃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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