Jim
Jim

Reputation: 121

API Gateway URI Versioning

I keep seeing comments on how to do URI versioning in API Gateway, and these all say the same thing,

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.

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 -> points to the prod stage of the Names V1 API

myapi.com/v2 -> points to the prod stage of the Names V2 API

However, when you try to create a Custom Domain Name with a "/" in it, API Gateway responds with "Invalid Domain Name". So if you try to do it on the mapping, you get something similar mentioning the special characters you can use, and "/" is not one of them. So your only option is to use the Stage variables which these posts mention the challenges of doing it that way.

Additionally, if you just make it "v1" with no slash, then we are unable to have a custom domain like "api.whatever.com". Then makes the custom domain be specific to an API area that needs to be versioned. Ex. "stores.whatever.com". This causes each API to have their own subdomain.

URI-based Versioning for AWS API Gateway API Versioning with AWS API Gateway

Sorry for asking a new question, but I'm not allowed to add a comment on the posts.

API Gateway Custom Domain Name Mapping

Upvotes: 2

Views: 1729

Answers (1)

DonBushell
DonBushell

Reputation: 1

I'm not sure I understand the request here, let me try to clarify. When a request comes in to your custom domain name api.whatever.com, API Gateway needs to determine where to send the request. API Gateway will look at the path and then determine if there are any API:STAGE mappings for that path. You can configure an empty base path mapping on a custom domain name, but then all requests without a path to that custom domain name will be routed to the API:STAGE mapping. It seems like you're trying to route requests to either api.whatever.com or stores.whatever.com, you can do this with two custom domain names each with their own empty base path mapping. For example:

Custom domain name1: api.whatever.com

  • api-id: 12345
  • stage: Live
  • api-mapping-key: NULL

Custom domain name2: stores.whatever.com

  • api-id: 67890
  • stage: Beta
  • api-mapping-key: NULL

Your clients will have to specify the proper domain name when calling your APIs.

Upvotes: 0

Related Questions