how to make AWS api gateway accept http instead of https

匿名 (未验证) 提交于 2019-12-03 08:57:35

问题:

I have a Lambda function proxied by API Gateway. However, API Gateway only expose https and not http. I searched everywhere but looks like API Gateway is not possible to accept http.

So my question is how to translate http client calls to https and send to api gateway? I am asking because my client can only make http calls and they won't change.

回答1:

I recently had a 4 hour long phone call with an AWS representative about a similar problem we had in production stage. My situation was similar, there was nothing we could change in APIGateway to fix it (the rep tried all kinds of tricks, but nothing seemed working). So our conclusion was to spin up an EC2 instance as a proxy server for APIGateway and forward all the traffic. There was some additional work such as transferring the domain name, but overall it worked just fine. In your case, as you only need to redirect HTTP traffic, a simple ElasticBeanstalk proxy app might be enough (EB uses HTTP by default and is behind a Nginx proxy server).



回答2:

You can put a Cloudfront distribution in front of API Gateway with to following setup:

  • Origin Protocol Policy: HTTPS Only
  • Viewer Protocol Policy: HTTP and HTTPS
  • Forward Headers: None
  • Object Caching: Use Origin Cache Headers


回答3:

CloudFront is a quick solution as it's much easier to set up compared to instantiating an Elastic Beanstalk.

I have spent couple of hours trying to get this right, so just to share some good write-ups and one more gentle reminder:

  1. This Smartcam project utilize Amazon API Gateway and CloudFront, it describes the setup procedure in details.
  2. The official example given in Amazon's doc demonstrates how to create GET and POST method with query string parameters (e.g. /search?keyword=mars&...), JSON payload and plus path parameters. Must read!
  3. Personal 2 cents:
    • if you are using query string parameters, make sure to edit behavior and then choose forward all, cache all under Query String Forwarding and Caching.
    • Alternatively, read this doc for another two possible configurations.
    • If you already set the Origin Path to your stage variable (by default: /prod), then when you invoke your CloudFront domain, skip the /prod, simply: xxxx.cloudfront.net/resource1/resource2?param1=...&param2=...


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!