首页 > 解决方案 > AWS API Gateway 在私有 VPC 中调用 api

问题描述

我在私有子网和 privateSG 的 ec2 上部署了一项服务。我可以从公共子网和 publicSG 中的 EC2 访问此服务。我想创建一个 API 网关,将这个 api 公开给我的客户[移动应用程序]。

实现这一目标的方法是什么?

我已经创建了 API 网关、资源和方法,但是这个 api 调用没有到达 ec2 上的服务。下面是错误

Wed Feb 17 10:14:38 UTC 2021 : Starting execution for request: c7290ccc-5859-44cf-bta2-90ff498cdec6
Wed Feb 17 10:14:38 UTC 2021 : HTTP Method: GET, Resource Path: /item/item-1
Wed Feb 17 10:14:38 UTC 2021 : Method request path: {id=item-1}
Wed Feb 17 10:14:38 UTC 2021 : Method request query string: {}
Wed Feb 17 10:14:38 UTC 2021 : Method request headers: {}
Wed Feb 17 10:14:38 UTC 2021 : Method request body before transformations: 
Wed Feb 17 10:14:38 UTC 2021 : Execution failed due to configuration error: Invalid endpoint address
Wed Feb 17 10:14:38 UTC 2021 : Method completed with status: 500```

标签: amazon-web-servicesaws-api-gateway

解决方案


要启用您的 API Gateway 访问您的私有实例,您可以设置API Gateway 私有集成

API Gateway 私有集成使您可以轻松地在 Amazon VPC 中公开您的 HTTP/HTTPS 资源,以供 VPC 外部的客户端访问。

另一种方法是使用与您的 VPC 集成的 lambda 函数作为代理。因此,您的 API 会调用该函数,而该函数又会在私有实例上调用您的 API 并将答案返回给 API。


推荐阅读