I am trying to serve lambda developed using serverless framework using two different custom domain names.
I added the following custom resources to my serverless.yml file:
Resources:
APIDomain1:
Type: AWS::ApiGateway::DomainName
Properties:
RegionalCertificateArn: !ImportValue TF-Cert
DomainName: 'api.domain1.com'
EndpointConfiguration:
Types:
- REGIONAL
APIDomain2:
Type: AWS::ApiGateway::DomainName
Properties:
RegionalCertificateArn: !ImportValue TF-Cert
DomainName: 'api.domain2.com'
EndpointConfiguration:
Types:
- REGIONAL
APIBasePathMapping1:
Type: AWS::ApiGateway::BasePathMapping
DependsOn: APIDomainMapping
Properties:
DomainName: 'api.domain1.com'
RestApiId:
Ref: ApiGatewayRestApi
Stage: ${self:provider.stage}
APIBasePathMapping2:
Type: AWS::ApiGateway::BasePathMapping
DependsOn: APIDomainMapping
Properties:
DomainName: 'api.domain2.com'
RestApiId:
Ref: ApiGatewayRestApi
Stage: ${self:provider.stage}
Unfortunately, when I try to deploy this stack I get this error message
APIBasePathMapping1 - api.domain1.com|(none) already exists in stack arn:aws:cloudformation:us-east-1:XXXXXXXX
I also see a corresponding event in the AWS Cloudformation console. As a result stack creating fails and I have neither domain mapped to the rest API
However, if I remove one of the AWS::ApiGateway::BasePathMapping from the serverless.yml deploy the stack and then manually add the domain mapping everything works as I want it to.
Is this a problem with serverless framework or cloudformation? Am I doing something wrong?