When creating a new RestApi, when a user tries to add a domain and configure that domain according to the documentation the process will fail due to an issue with BasePathMapping (Only one base path mapping is allowed if the base path is empty). However, the user is not given an opportunity to supply a basepath for the domain before the default 'empty' base path is created which results in an error
api = new apigw.LambdaRestApi( this, "proxy_api", {
handler: props.function.lambdaFn,
restApiName: 'apiname',
proxy: true,
endpointTypes: [ apigw.EndpointType.EDGE ]
} );
var domainName = this.api.addDomainName("domain_name", {
domainName: "example.com",
certificate: certificate,
endpointType: apigw.EndpointType.EDGE, // default is REGIONAL,
securityPolicy: apigw.SecurityPolicy.TLS_1_2,
});
domainName.addBasePathMapping( api, { basePath: 'foo'});
I expected to be able to add the basePath foo
Only one base path mapping is allowed if the base path is empty. (Service: AmazonApiGateway; Status Code: 409; Error Code: ConflictException; Request ID: a2d4de69-74d0-4870-90f4-78d7d4017925)
This is :bug: Bug Report
I managed to document the process for successfully creating a domain using CDK:
https://medium.com/@gregorypierce/cdk-restapi-custom-domains-554175a4b1f6?sk=197a9e2df62fd27c865e34951d8efad2
But one thing you'll notice if you follow the steps is that you will end up with a spare customdomain that is pointed to "nothing". There doesn't appear to be any way to avoid it. Since the A record is pointing to the appropriate location it works, so if you just never create the associated A record things will be okay - but that extra DomainName really shouldn't be there.
Encountered the same issue.
| CREATE_IN_PROGRESS | AWS::ApiGateway::BasePathMapping | api/CustomDomain/Map:--=> default apigw base_path
| CREATE_IN_PROGRESS | AWS::ApiGateway::BasePathMapping | api/CustomDomain/Map:foo=> user define base_path
Maybe we can have base_path parameter in DomainNameOptions to override the default base path mapping when defining DomainName via DomainNameOptions .
Or addBasePathMapping should override the default base_path.
Also ran into this issue. Documentation is misleading.
Most helpful comment
Also ran into this issue. Documentation is misleading.