Monday, 25 October 2021

How to Enable multi level path mapping in Aws Api Gateway?

When trying to map basepath in ApiGateway in was by using cloud formation, it was giving error 

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;

Previous code

  BasePathMappings:
    Type: AWS::ApiGateway::BasePathMapping
    DependsOn: ApplicationApi
    Properties:
      BasePath: "path/route"
      DomainName: "api.CustomDomainName.com"
      RestApiId: !Ref ApplicationApi
      Stage: Prod

Modified code (Solution)
  BasePathMappings:
    Type: AWS::ApiGatewayV2::ApiMapping
    DependsOn: ApplicationApi
    Properties:
      ApiMappingKey: "path/route"
      DomainName: "api.CustomDomainName.com"
      ApiId: !Ref ApplicationApi
      Stage: Prod


References: