question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(aws-apigateway v1): Support for multi-level paths in BasePathMapping

See original GitHub issue

I would like to have the possibility to add a multi-level path in BasePathMapping for Api gateway v1, as already stated in #14822 (but closed in favour of a new feature request like this)

Use Case

The specific case I’m trying to cover is:

  • edge optimized domain name
  • edge REST api endpoint
  • multi-level path mapping

We are using apigateway v1

Proposed Solution

I tried a couple of workarounds:

Tried to use v1 BasePathMapping but got this error:

Mapping API Gateway V1 doesn't support the slash character (/) in base path mappings. To create a multi-level base path mapping, use API Gateway V2.

Tried to switch to v2 with CfnApiMapping and got this error:

Mapping Only REGIONAL domain names can be managed through the API Gateway V2 API. For EDGE domain names, please use the API Gateway V1 API. Also note that only REST APIs can be attached to EDGE domain names.

  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

This is a 🚀 Feature Request

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:25
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
ilazakiscommented, Apr 13, 2022

+1 on supporting this on v1.

2reactions
JonBlauveltcommented, Feb 11, 2022

In the AWS console, I was able to change base path from foo-bar to foo/bar. Therefore, I would say that it is supported by API Gateway v1. However, CloudFormation does not support it at the moment.

This isn’t quite right. Here’s what’s supported by APIGateway for RestAPI - you can create a multi-part mapping if the following conditions are met:

  1. You have a REGIONAL endpoint (this is the default configuration with DomainName Construct)
  2. You have TLS 1.2 (this is non-default)
  3. You use ApiMapping from api-gatewayv2

This error message:

API Gateway V1 doesn't support the slash character (/) in base path mappings.
To create a multi-level base path mapping, use API Gateway V2.
(Service: AmazonApiGateway; Status Code: 400; Error Code: BadRequestException;
Request ID: a32ebc67-9e1a-44bb-af38-011820b127b1; Proxy: null)

Is an indication that condition 3 is not met. That is, you are trying to add a multipart mapping via apigateway v1’s base path mapping, which is not supported. The reason that adding the mapping from the console succeeds is because it is adding an apigatewayv2 apiMapping to your RestApi(apigatewayv1), which is supported, though this is not transparent.

So assuming other conditions are met, you can attach a multipart apigatewayv2 api mapping to your restApi/domainname. However, you will need to use the L1 (Cfn) constructs or roll your own adapter since the L2 constructs for apigateway and apigatewayv2 are not interoperable here.

It seems like it may make sense to build support for this use case in the L2 constructs. Some possible approaches:

  1. apigatewayv1 DomainName constructor to support creating apigatewayv2 ApiMappings either explicitly through an additional config or implicitly for multipart use case
  2. apigatewayv1 DomainName.addBasePathMapping to support creating apigatewayv2 ApiMappings either explicitly through an additional config or implicitly for multipart use case
  3. new method on apigatewayv1 DomainName i.e. DomainName.addApiMapping to support adding v2 mapping to v1 api+domainname
  4. apigatewayv2.ApiMapping constructor to support passing V1 DomainName and api

However, the original feature request looks to be about specifically allowing for multipart mappings for edge api/domain which is a limitation of ApiGateway, not a limitation of CDK or CFN, so I don’t think that can be solved here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

(aws-apigateway): Support for multi-level paths in ... - GitHub
API Gateway V1 doesn't support the slash character (/) in base path mappings. To create a multi-level base path mapping, use API Gateway...
Read more >
How does one create multi-level base path mapping for REST ...
I ran into this article which indicates you will need to call the apigatewayv2 call. The interesting thing is that the V2 is...
Read more >
AWS Api gateway for REST API does not work with multi-level ...
I am currently trying to use aws api gateway CLI to create a multi-level base path mapping. I am running the following command:...
Read more >
Amazon API Gateway custom domain names now support ...
Amazon API Gateway custom domain names now support multi-level base path mappings. You can now configure each path segment of an API Gateway ......
Read more >
How to Enable multi level path mapping in Aws Api Gateway?
API Gateway V1 doesn't support the slash character (/) in base path mappings. To create a multi-level base path mapping, use API Gateway...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found