可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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:
- This Smartcam project utilize Amazon API Gateway and CloudFront, it describes the setup procedure in details.
- 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!
- 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=...¶m2=..
.