我按照说明为我的 Amazon API Gateway REST 或 HTTP API 设置了自定义域名。我在调用 API 时收到 403“Missing Authentication token”(缺少身份验证令牌)错误。
简短描述
如果 URL 路径不正确,具有自定义域名的 API Gateway API 在调用 API 时将返回 403“Missing Authentication token”(缺少身份验证令牌)错误。
**注意:**使用 API Gateway API 阶段 URL 不会返回 403“Missing Authentication token”(缺少身份验证令牌)错误。
解决方法
为 API Gateway API 配置的自定义域名使用 API 映射来连接 API 阶段,以通过自定义域名向 API 发送流量。API 映射具有用于映射的 API、阶段、自定义域名以及路径(可选)。有关详细信息,请参阅使用 API 映射。
在以下示例中,自定义域“https://api.example.com”API 映射配置如下:
| | | | | |
---|
API | 示例 | 阶段 | 路径 | 默认 URL | 自定义域 URL |
abcd3456ef | API 1 | dev | (none) | https://abcd3456ef.execute-api.us-east-1.amazonaws.com/dev | https://api.example.com |
wxyz1234ab | API 2 | test | orders | https://wxyz1234ab.execute-api.us-east-1.amazonaws.com/test | https://api.example.com/orders |
mnop5678qr | API 3 | prod | customers | https://mnop5678qr.execute-api.us-east-1.amazonaws.com/prod | https://api.example.com/customers |
在此示例配置中,使用 URL https://abcd3456ef.execute-api.us-east-1.amazonaws.com/dev/resourceA 向 API 1 发出的请求可成功将流量路由到“resourceA”。这是因为请求是向阶段名称为“dev”的资源发出的。但是,使用 URL https://api.example.com/dev/resourceA 发出的相同请求将返回 403“Missing Authentication token”(缺少身份验证令牌)错误。发生此错误是因为阶段“dev”被映射到自定义域名的 (none) 路径。要使用自定义域名将请求路由到“ResourceA”,请确保 URL 为 https://api.example.com/resourceA。
同样,与 https://wxyz1234ab.execute-api.us-east-1.amazonaws.com/test/resourceB 等同的自定义域名 URL 为 https://api.example.com/orders/resourceB。这是因为在自定义域 API 映射中,API 2 的“test”阶段映射到路径“orders”。
相关信息
如何解决来自 API Gateway 的 HTTP 403 错误?
如何故障排除 API Gateway REST API 端点 403“Missing Authentication Token”错误?
在 API Gateway 中设置区域自定义域名