AWS CDK : Only one base path mapping is allowed if the base path is empty in Typescript

Viewed 286

I am trying to setup a REST API using the AWS CDK like this:

    // create our REST-API Gateway
    const restApi = new apigateway.RestApi(this, `api-gateway-${props?.stage}`, {
      deployOptions: {
        stageName: props?.stage || 'prod'
      }
    });
    
    // Create a custom domain and use the newly created certificate with it
    const apiDomain = new apigateway.DomainName(this, `api-domain-${props?.stage}`, {
      domainName: apiDomainName,
      certificate: certificate,
      endpointType: apigateway.EndpointType.EDGE,
      securityPolicy: apigateway.SecurityPolicy.TLS_1_2
    });
    apiDomain.addBasePathMapping(restApi, {
      basePath: 'api'
    });

but this results in:

Only one base path mapping is allowed if the base path is empty. (Service: AmazonApiGateway; Status Code: 409; Error Code: ConflictException; Request ID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx; Proxy: null)

It seems as if empty basePath mapping is created automatically, therefore the second one can not be added.

Even a clean run in a clean account brings the same error. How do I avoid this error? is there any other way to add a base path? Any way to avoid the default empty one?


  • aws-cdk: 1.75.0 (build 7708242)
  • @aws-cdk/aws-apigateway : 1.75.0
0 Answers
Related