简体   繁体   English

无法从在 vpc 后面的 ec2 上运行的应用程序访问 aws api 网关上的公共 api

[英]Unable to access public api on aws api gateway from app running on an ec2 behind vpc

I have an created a public aws api gateway which i have have tested and works with an app deployed on my local and with curl我创建了一个公共 aws api 网关,我已经对其进行了测试,并与部署在本地和 curl 上的应用程序配合使用

But when i deploy the app on the ec2 on a vpc it cannot query that public api i get 403 forbidden但是当我在 vpc 上的 ec2 上部署应用程序时,它无法查询公共 api 我得到 403 forbidden

Is there any reason as to why i cannot query this api ?为什么我不能查询这个 api 有什么原因吗?

From more debugging i did i created another private api which i can access from the ec2 behind the vpc and everything works fine通过更多的调试,我创建了另一个私有 api,我可以从 vpc 后面的 ec2 访问它,并且一切正常

I also tried running some curl requests to another public api and that works我还尝试向另一个公共 api 运行一些 curl 请求并且有效

It seems my issue is with when access public regional aws api gateway from a vpc看来我的问题是何时从 vpc 访问公共区域 aws api 网关

Based on the comments, the issue was that the access to regional API was blocked by the VPC interface gateway.根据评论,问题是 VPC 接口网关阻止了对区域 API 的访问。 As explained here the presence of the gateway is going to block the access to regional and edge APIs.正如解释这里的网关的存在是要阻止进入区域和边缘的API。

The solution for now is to use private API gateway endpoint :现在的解决方案是使用私有 API 网关端点

An API endpoint that is exposed through interface VPC endpoints and allows a client to securely access private API resources inside a VPC.通过接口 VPC 端点公开的 API 端点,并允许客户端安全地访问 VPC 内的私有 API 资源。 Private APIs are isolated from the public internet, and they can only be accessed using VPC endpoints for API Gateway that have been granted access.私有 API 与公共 Internet 隔离,只能使用已授予访问权限的 API 网关的 VPC 端点访问它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM