AWS API Gateway Proxy Response failure/dropped

不打扰是莪最后的温柔 提交于 2019-12-04 13:27:08

Quick answer: add header Accept-Encoding:identity

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.

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).

  1. curl and Postman/browser are both ultimately making HTTP requests to your API Gateway so the task is to figure out what the difference(s) in the requests are. If you run curl with the -v flag you will get verbose output that will include all of the headers sent with the request. Postman/browsers should have something similar, please compare them and you should find a difference. Also to eliminate the custom domain being a possible issue, have you tried making the request to your non-custom domain (*.execute-api) URI?

  2. See 1.

  3. Make sure your proxy method has the "API Key required" checkbox selected.
  4. If you're using mapping template transformations, you'll have to set up a template for each content type you expect to be received from client requests. If you're not using transformations make sure WHEN_NO_TEMPLATE ("When there are no templates defined (recommended)" in the Console UI) passthrough behavior is selected for the integration request. See: 1 and 2

I had the same problem.

The solution that worked for our use case was to disable compression on the Application server. And then enable the Content Encoding feature from AWS API Gateway settings:

Don't forget to redeploy your API Stage from the resources section !!

For your Express.js API Endpoint which is running in AWS Lambda and proxyed through API Gateway, you can modify the app.js to look like this:

   const compression = require('compression');
   if (!process.env.LAMBDA_TASK_ROOT) {
      app(compression()); // compression is only enabled when not in Lambda
   }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!