how to make AWS api gateway accept http instead of

2020-05-26 05:13发布

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.

3条回答
Juvenile、少年°
2楼-- · 2020-05-26 05:34

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

查看更多
狗以群分
3楼-- · 2020-05-26 05:37

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 cloudfront panel and then choose forward all, cache all under Query String Forwarding and Caching.querystring forwarding choice
    • 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=...origin path screenshot
查看更多
Rolldiameter
4楼-- · 2020-05-26 05:41

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
查看更多
登录 后发表回答