Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error: api.mydomain.com already exists in stack arn:aws:xyz #1028

Closed
mdesousa opened this issue Nov 21, 2023 · 2 comments
Closed

error: api.mydomain.com already exists in stack arn:aws:xyz #1028

mdesousa opened this issue Nov 21, 2023 · 2 comments
Assignees
Labels
bug Something isn't working needs-triage The issue or PR still needs to be triaged

Comments

@mdesousa
Copy link

Create two stacks with 2 instances of ApiGatewayToLambda()

In the first instance, configure a domain name like this:

apiGatewayProps: { domainName: { domainName: 'api.mydomain.com', certificate: { certificateArn } }

The second instance should be on the same domain name, but on a different path:

apiGatewayProps: { domainName: { domainName: 'api.mydomain.com', basePath: 'mypath', certificate: { certificateArn } }

This should be supported since api gateway supports having a domain with mappings to multiple APIs.
Instead, we get an error when the second stack is being deployed: "api.mydomain.com already exists in stack arn:aws:xyz"

Thanks!

@mdesousa mdesousa added bug Something isn't working needs-triage The issue or PR still needs to be triaged labels Nov 21, 2023
@biffgaut
Copy link
Contributor

Thanks - we'll take a look.

@biffgaut biffgaut self-assigned this Nov 22, 2023
@biffgaut
Copy link
Contributor

This appears to be a limitation at the CDK level. This code attempts to launch 2 RestAPIs with the same domain name using just CDK L2 constructs and sees the same behavior.

export class Issue1028Stack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const functionOne = new lambda.Function(this, 'function-one',
    {
       code: lambda.Code.fromAsset(`lambda`),
       runtime: lambda.Runtime.NODEJS_18_X,
       handler: 'indexOne.handler',
    })

    const myCert = cert.Certificate.fromCertificateArn(this, 'fake-cert', 'real cert arn omitted');
    const propsOne: api.RestApiProps = {
      domainName: { 
        domainName: 'testdomain.net',
        certificate:myCert
      }
    }
    const apiOne = new api.RestApi(this, 'one', propsOne);
    apiOne.root.addMethod('GET', new api.LambdaIntegration(functionOne));


    const functionTwo = new lambda.Function(this, 'function-two',
    {
       code: lambda.Code.fromAsset(`lambda`),
       runtime: lambda.Runtime.NODEJS_18_X,
       handler: 'indexTwo.handler',
    })

    const propsTwo: api.RestApiProps = {
      domainName: { 
        domainName: 'testdomain.net',
        certificate:myCert,
        basePath: 'subSite'
      }
    }
    const apiTwo = new api.RestApi(this, 'two', propsTwo);
    apiTwo.root.addMethod('GET', new api.LambdaIntegration(functionTwo));
  }
}

@biffgaut biffgaut closed this as completed Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-triage The issue or PR still needs to be triaged
Projects
None yet
Development

No branches or pull requests

2 participants