使用 AWS Route 53 路由到 API 网关
Routing to API gateway using AWS Route 53
我在所有 AWS 区域都有一个 lambda 函数。我的客户遍布全球,他们将 POST 调用我的基本域 example.com
。我的(某种)负载均衡器有责任确保将请求路由到离客户端最近的区域的 API 网关,以最大程度地减少延迟。
所以,到目前为止我有以下配置:
- 部署在每个区域的 Lambda 函数
- 每个 API 网关的自定义域名,公开一个 CloudFront 域名。例如,N.California 区域配置了自定义域名
us-west-1.example.com
和调用我的 lambda 的路径映射。此 API 网关的 CloudFront URL 是 d12345123.cloudfront.net
us-west-1.example.com
的 Route53 托管区域中 A
类型的 RecordSet,它是 d12345123.cloufront.net
的别名。如果我对 us-west-1.example.com/1.0/localdb
进行 POST 调用,它 returns 我得到正确的输出。
- Route53 中的流量策略和策略记录,用于
A
类型的 default.example.com
,它分配有地理邻近规则,将流量重定向到 CloudFront 实例(在该区域添加自定义域名后暴露的相同实例)。这会在 A
类型的托管区域中为 default.example.com
创建一个条目
example.com
的 Route53 托管区域中 A
类型的 RecordSet,它是 default.example.com
的别名,因此到达 example.com
的流量可以路由到 default.example.com
在这些配置之后,当我调用 example.com
时,我收到来自 Cloudfront 的 403
响应,称其为 Bad Request
谢谢
截至 2017 年 11 月“亚马逊 API 网关支持区域 API 端点”
You can now choose from two types of API endpoints when creating REST APIs and custom domains with Amazon API Gateway. A regional API endpoint is a new type of endpoint that is accessed from the same AWS region in which your REST API is deployed. This helps you reduce request latency when API requests originate from the same region as your REST API. Additionally, you can now choose to associate your own Amazon CloudFront distribution with the regional API endpoint. The second type of API endpoint is the edge-optimized API. Edge-optimized APIs are endpoints that are accessed through a CloudFront distribution that is created and managed by API Gateway. Previously, edge-optimized APIs were the default option for creating APIs with API Gateway.
To get started, create a new REST API using the Amazon API Gateway console, AWS CLI, or AWS SDKs and APIs. You can also migrate existing REST APIs and custom domains to a regional API endpoint. Visit our documentation to learn more about this feature.
This feature is now available in US East (N. Virginia), US East (Ohio), US West (Oregon), US West (N. California), Canada (Central), South America (São Paulo), EU (Ireland), EU (Frankfurt), EU (London), Asia Pacific (Singapore), Asia Pacific (Tokyo), Asia Pacific (Sydney), Asia Pacific (Seoul), and Asia Pacific (Mumbai) AWS regions. Visit our product page for more information about Amazon API Gateway.
我在所有 AWS 区域都有一个 lambda 函数。我的客户遍布全球,他们将 POST 调用我的基本域 example.com
。我的(某种)负载均衡器有责任确保将请求路由到离客户端最近的区域的 API 网关,以最大程度地减少延迟。
所以,到目前为止我有以下配置:
- 部署在每个区域的 Lambda 函数
- 每个 API 网关的自定义域名,公开一个 CloudFront 域名。例如,N.California 区域配置了自定义域名
us-west-1.example.com
和调用我的 lambda 的路径映射。此 API 网关的 CloudFront URL 是d12345123.cloudfront.net
us-west-1.example.com
的 Route53 托管区域中A
类型的 RecordSet,它是d12345123.cloufront.net
的别名。如果我对us-west-1.example.com/1.0/localdb
进行 POST 调用,它 returns 我得到正确的输出。- Route53 中的流量策略和策略记录,用于
A
类型的default.example.com
,它分配有地理邻近规则,将流量重定向到 CloudFront 实例(在该区域添加自定义域名后暴露的相同实例)。这会在A
类型的托管区域中为 example.com
的 Route53 托管区域中A
类型的 RecordSet,它是default.example.com
的别名,因此到达example.com
的流量可以路由到default.example.com
default.example.com
创建一个条目
在这些配置之后,当我调用 example.com
时,我收到来自 Cloudfront 的 403
响应,称其为 Bad Request
谢谢
截至 2017 年 11 月“亚马逊 API 网关支持区域 API 端点”
You can now choose from two types of API endpoints when creating REST APIs and custom domains with Amazon API Gateway. A regional API endpoint is a new type of endpoint that is accessed from the same AWS region in which your REST API is deployed. This helps you reduce request latency when API requests originate from the same region as your REST API. Additionally, you can now choose to associate your own Amazon CloudFront distribution with the regional API endpoint. The second type of API endpoint is the edge-optimized API. Edge-optimized APIs are endpoints that are accessed through a CloudFront distribution that is created and managed by API Gateway. Previously, edge-optimized APIs were the default option for creating APIs with API Gateway.
To get started, create a new REST API using the Amazon API Gateway console, AWS CLI, or AWS SDKs and APIs. You can also migrate existing REST APIs and custom domains to a regional API endpoint. Visit our documentation to learn more about this feature.
This feature is now available in US East (N. Virginia), US East (Ohio), US West (Oregon), US West (N. California), Canada (Central), South America (São Paulo), EU (Ireland), EU (Frankfurt), EU (London), Asia Pacific (Singapore), Asia Pacific (Tokyo), Asia Pacific (Sydney), Asia Pacific (Seoul), and Asia Pacific (Mumbai) AWS regions. Visit our product page for more information about Amazon API Gateway.