AWS API Gateway代理响应失败/已删除 [英] AWS API Gateway Proxy Response failure/dropped

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

问题描述

问题 :

Problem:

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

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

说明 :

Description:

我有一个要通过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. 可以从部署阶段的网址成功调用我的后端服务
  6. 使用CA证书创建自定义域
  7. 在我的DNS提供商上创建别名
  8. 1小时后,域启动并指向云前端

问题

我拨打了自定义域的电话

I made a call to the custom domain,

  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到我的端点有什么问题?

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

为什么卷曲成功?

,对于我的API Gateway端点,我已将API Key设置为必选.我创建了一个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 Gateway代理响应失败/已删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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