假设我需要一个将运行 Lambdas 的 API 网关,并且我想构建最佳的全局分布式性能基础设施。此外,我将使用 Cognito 进行身份验证,使用 Dynamodb 和 S3 进行用户数据和前端静态分析。
我的应用程序位于 myapp.com
首先用户从最近的位置获取静态前端:
用户 ===> CloudFront 的边缘位置 <--- S3 在任何区域(带有静态前端)
之后我们需要与API Gateway通信。
用户 ===> API 网关 ---> Lambda ---> S3 ||认知 || Dynamodb
API 网关可以位于多个区域,即使与 CloudFront 一起分发,每个端点都指向位于给定区域的 Lambda:假设我在 eu-west-1 部署了一个 API。如果请求是从美国发送的,即使我的 API 在 CloudFront 上,它运行的 Lambda 位于 eu-west-1,所以无论如何延迟都会很高。
为避免这种情况,我需要在 us-east-1 和我所有的 Lambda 上部署另一个 API。该 API 将指向那些 Lambdas
如果我为每个区域部署一个 API,则每个区域都需要一个端点,前端应决定请求哪一个。但是我们怎么知道哪一个是最近的位置呢?
理想的场景是位于 api.myapp.com
的单个全局端点,它将转到最近的 API 网关,该网关也运行位于该区域的 Lambda。我可以使用 Route 53 延迟路由和指向每个 api 网关的多个 A 记录来配置它吗?
如果这不是正确的方法,您能指出正确的方向吗?
最佳答案
AWS 最近宣布支持区域 API 端点,您可以使用它来实现这一目标。
下面是一个 AWS 博客,解释了如何实现这一点:
Building a Multi-region Serverless Application with Amazon API Gateway and AWS Lambda
博客摘录:
The default API endpoint type in API Gateway is the edge-optimized API endpoint, which enables clients to access an API through an Amazon CloudFront distribution. This typically improves connection time for geographically diverse clients. By default, a custom domain name is globally unique and the edge-optimized API endpoint would invoke a Lambda function in a single region in the case of Lambda integration. You can’t use this type of endpoint with a Route 53 active-active setup and fail-over.
The new regional API endpoint in API Gateway moves the API endpoint into the region and the custom domain name is unique per region. This makes it possible to run a full copy of an API in each region and then use Route 53 to use an active-active setup and failover.
关于amazon-web-services - 使用 API Gateway、Lambda、Cognito、S3、Dynamodb 部署 AWS 全局基础设施,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39787591/