了解 AWS API Gateway 自定义域名 [英] Understanding AWS API Gateway Custom Domain Names

查看:52
本文介绍了了解 AWS API Gateway 自定义域名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难理解 AWS API Gateway 自定义域的工作原理.

I am struggling to understand how AWS API Gateway Custom Domain works.

我已经为我的 api 设置了一个 区域自定​​义域名,例如 api.example.com.结果是一个Target Domain Name,格式为:

I have set up a Regional Custom Domain Name for my api, like api.example.com. The result is a Target Domain Name in the form of:

aaaaaaaaaaaa.execute-api.us-east-1.amazonaws.com

如果我尝试使用此链接调用 API,例如:

If I try to invoke the API using this link, such as in:

https://aaaaaaaaaaaa.execute-api.us-east-1.amazonaws.com/mymap/mystage/example

但我收到一个403 Forbidden.

但是,如果我去 Stages 并选择 mystage 有一个大的蓝色 Invoke URL 形式为:

BUT, if I go to Stages and select mystage there's a big blue Invoke URL in the form of:

https://bbbbbbbbbb.execute-api.us-east-1.amazonaws.com/mymap/mystage/example

哪个有效!

我的前两个问题来了:

1 - 为什么 API Gateway 会为同一个 API(Target Domain NameInvoke URL)生成 2 个不同的 URL?

1 - Why does API Gateway generate 2 different URLs for the same API (the Target Domain Name and the Invoke URL)?

2 - 为什么 Invoke URL 有效而 Target Domain Name 无效?

2 - Why does the Invoke URL works and the Target Domain Name doesn't?

这是我问题的第二部分,我正在尝试为 Regional Custom Domain Name 配置配置 Route 53,但我找不到任何关于正确的方法(仅适用于 Edge Optimized Custom Domain Name).

Here's the second part of my question, I am trying to configure Route 53 for the Regional Custom Domain Name configuration, but I can't find any examples about the right way to do it (just for Edge Optimized Custom Domain Name).

我尝试为 api.example.com 创建一个 A 记录作为 Aliasaaaaaaaaaaaa.execute-api.us-east-1.amazonaws.com,但它说:

I tried to create an A record for api.example.com as an Alias to aaaaaaaaaaaa.execute-api.us-east-1.amazonaws.com, but it says:

无法保存记录集,因为:- 别名目标包含无效值.

The record set could not be saved because: - Alias Target contains an invalid value.

所以我为 api.example.com 创建了一个 CNAME 记录,将 Alias 设置为 No(设置作为 Yes 带来与 A 记录案例中相同的错误消息)和 aaaaaaaaaaaa.execute-api.us-east-1.amazonaws 的值.com 但是当我尝试以 https://api.example.com/mymap/mystage/example 调用我的 API 时,我得到一个 404.

So I created a CNAME record for api.example.com, setting Alias to No (setting as a Yes brings the same error message as in the A record case) and the value as aaaaaaaaaaaa.execute-api.us-east-1.amazonaws.com but then I get a 404 when I try to invoke my API as https://api.example.com/mymap/mystage/example.

我做错了什么?

此主题已移至 AWS 论坛此处

This thread was moved to the AWS Forums here

编辑 2:

显然,正如 AWS 支持人员所说,API Gateway 如何处理自定义域名和常规 API Gateway URL 存在不一致,所有这些都记录在此 AWS 论坛主题 这里

Apparently, as the AWS support guys said, there is an inconsistency on how API Gateway treats Custom Domain Names and regular API Gateway URLs, all is documented at this AWS Forum thread here

推荐答案

如果有人想了解 API Gateway 发生了什么,请查看 此线程.

If anyone wants to understand what was going on with API Gateway, take a look at this thread.

基本上是说 API Gateway 处理常规 URL(例如 aaaaaaaaaaaa.execute-api.us-east-1.amazonaws.com)与处理自定义域名 URL(例如 api.myservice.com).因此,当 API Gateway 将您的 API 请求转发到您的 Lambda 函数时,您的 Lambda 函数将收到不同的 path 值,具体取决于您用于调用 API 的 URL 类型.

It basically says that API Gateway processes regular URLs (like aaaaaaaaaaaa.execute-api.us-east-1.amazonaws.com) differently than how it processes Custom Domain Name URLs (like api.myservice.com). So when API Gateway forwards your API request to your Lambda Function, your Lambda Function will receive different path values, depending on which type of your URL you used to invoke your API.

就我而言,我使用的是 无服务器 Java 容器,因此我可以在 AWS Lambda 上运行 Jersey 网络服务.由于传递给两个 URL 的 URL 不同,Jersey 将在收到与其配置格式错误的 URL 时返回 404.

In my case I am using the serverless java container, so I can run a Jersey webservice on AWS Lambda. Since the URL is not being passed the same for both URLs, Jersey will return a 404 when it receives an URL that is malformed for its configuration.

AWS API Gateway 团队表示他们正在考虑使这种 URL 调用统一,但到目前为止(2018 年 1 月)没有妥协.

The AWS API Gateway team said their are thinking about making this URL invocation uniform, but no compromises on it so far (January 2018).

我问题的 53 号公路部分由杰克回答,我没有什么可补充的.

The Route 53 part of my question is answered by Jack and I have nothing to add.

这篇关于了解 AWS API Gateway 自定义域名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆