AWS API Gateway 基于 URI 的版本控制 [英] URI-based Versioning for AWS API Gateway

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

问题描述

我正在努力理解 AWS API Gateway 如何让我组织我的 API,从而使版本控制变得简单明了.例如,假设我有一个用于从字典中获取单词的简单 API,可以选择通过查询参数过滤结果.我希望在以下位置提供 v1:

I am struggling to understand how AWS API Gateway wants me to organise my APIs such that versioning is straightforward. For example, let's say I have a simple API for getting words from a dictionary, optionally filtering the results by a query parameter. I'd like to have v1 of this be available at:

https://<my-domain>/v1/names?starts-with=<value>

然而,我能得到的最接近 API Gateway 是在

However, the closest I can get API Gateway is at

https://<my-domain>/names/v1?starts-with=<value>

...这是相当倒退.

我在控制台中得到的是Names API",带有支持 GET 方法的v1"资源.我也有我的自定义域设置来将名称"的基本路径映射到名称 API"和阶段测试".基本路径必须是唯一的,因此放置v1"只会获得短期胜利;一旦我创建了我的第二个 API(例如 Numbers API),它也会有一个 v1,我将无法创建第二个映射.

What I've got in the console is "Names API" with a "v1" resource supporting a GET method. I also have my custom domain setup to map a base path of "names" to "Names API" and stage "test". The Base path must be unique so putting "v1" there is only a short-term win; once I create my second API (e.g. Numbers API) it'll have a v1, too, and I won't be able to create a second mapping.

非常感谢任何和所有帮助,因为我现在没有想法.

Any and all help is greatly appreciated as I'm out of ideas now.

推荐答案

不要将版本路径 (/v1) 创建为 API 中的资源.相反,只需调用 APINames V1"并开始创建资源 (/names).当您想要进行重大更改并创建 API 的新版本时,我们建议您创建一个名为Names V2"的全新 API.再一次,只需在没有版本路径的情况下创建您的资源.

Do not create the version path (/v1) as a resource in your API. Instead, simply call you API "Names V1" and start creating the resources (/names). When you want to make a breaking change and create a new version of the API, we recommend you create an entirely new API called "Names V2". Once again, simply create your resources without the version path.

要将这两个 API 结合在一起,您可以使用自定义域名.API Gateway 中的自定义域名包括完全限定域名和基本路径.创建两个自定义域名:

To bring the two APIs together, you can use custom domain names. A custom domain name in API Gateway includes both a fully qualified domain name and a base path. Create two custom domain names:

  • myapi.com/v1 -> 指向 Names V1 API 的 prod 阶段
  • myapi.com/v2 -> 指向 Names V2 API 的 prod 阶段

通过这种方式,您可以在对 v2 进行更改的同时继续修复错误 v1,并独立部署这两个 API.自定义域名会将它们组合在一起并使它们出现在同一个域 (myapi.com/v2/names) 下.

This way you can keep bug-fixing v1 while making changes to v2 and deploy the two APIs independently. The custom domain name will bring them together and make them appear under the same domain (myapi.com/v2/names).

希望这会有所帮助.

这篇关于AWS API Gateway 基于 URI 的版本控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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