amazon-web-services - 使用 API Gateway、Lambda、Cognito、S3、Dynamodb 部署 AWS 全局基础设施

标签 amazon-web-services aws-lambda aws-api-gateway amazon-route53

假设我需要一个将运行 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/

相关文章:

amazon-web-services - 如何通过 AWS EKS 在 ECR 中使用 Docker 镜像

java - 减少来自 Java Lambda 的 DynamoDB 延迟

aws-lambda - CloudFormation 自定义资源未完成删除

java - aws api 网关速度中的转义字符

jquery - 尽管可以使用 CURL 进行 POST,但使用 CORS 到 API 网关的 AJAX POST 不起作用

amazon-web-services - AWS API Gateway 自定义授权方日志

image - Amazon S3 中合理的文件命名

amazon-web-services - AWS PowerUserAccess 在创建 VM 时无法列出角色,但策略将其显示为允许

node.js - 在 Node.js 中使用 async/await 的 Lambda 授权方响应

amazon-web-services - Redshift 复制和卸载安全性