我创建了一个 API 网关来运行 Lambda 函数。这意味着用作内部服务,因此我的 API 网关是私有(private)的。为了使 API 网关可以私下访问,我执行了以下操作:
这些步骤有效地阻止公共(public)请求,并允许通过 VPC 终端节点创建的 DNS 名称来自本地的请求。
这种方法的问题是为了调用 API,必须指定
Host
或 x-apigw-api-id
在请求中。目标是让用户能够在他们的浏览器上输入 URL 和查询字符串参数,并从服务中获得响应。Amazon API Gateway types, use cases and performance讨论了一种避免指定 API id 或主机的方法,但它没有提供太多细节。相关部分说解决方案是:
Place an Application Load Balancer with an SSL certificate (e.g. api.mydomain.com) in front of the IP addresses of your PrivateLink network interfaces. Also deploy a custom domain name for api.mydomain.com and a base path mapping for your API Gateway. Then add a Route 53 record that points api.mydomain.com as an alias to your ALB. This solution is quite complex, but we’ve tested it and it works. Describing the full solution is outside the scope of this post, but we might write a separate blog post about it later.
有谁知道如何做到这一点或不同的方法?
最佳答案
我找到了这个问题的答案,所以我想我应该分享它,以防其他人想知道如何做到这一点。我联系了上面写这篇文章的人,他给了我一些指示。他后来写了一篇解释解决方案的帖子,如果我的总结令人困惑,你可以在这里阅读他的帖子:
https://cloudbanshee.com/blog/connecting-to-private-api-over-vpn-or-vpc-peering
本质上,一旦您拥有私有(private) API Gateway VPC 端点和 ALB,您需要执行以下操作:
我缺少并使这项工作有效的是基本路径映射。这就是 ALB 在不知道任何 ID 或主机名的情况下知道将流量路由到哪个 API 网关的方式。
我分享的帖子更详细,写得更好。我建议任何有兴趣学习如何私下访问 API 网关的人来阅读它。
关于amazon-web-services - 如何通过本地/VPN 访问私有(private) API 网关?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56246494/