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

(cloudfront): custom EdgeFunction aliases clash #13237

Closed
arjunnaha opened this issue Feb 23, 2021 · 2 comments · Fixed by #13324
Closed

(cloudfront): custom EdgeFunction aliases clash #13237

arjunnaha opened this issue Feb 23, 2021 · 2 comments · Fixed by #13324
Assignees
Labels
@aws-cdk/aws-cloudfront Related to Amazon CloudFront bug This issue is a bug. effort/small Small work item – less than a day of effort in-progress This issue is being actively worked on. p1

Comments

@arjunnaha
Copy link

arjunnaha commented Feb 23, 2021

When using multiple CloudFront EdgeFunction's with custom aliases, the physical names conflict.

Reproduction Steps

import * as cloudfront from "@aws-cdk/aws-cloudfront";
import * as origins from "@aws-cdk/aws-cloudfront-origins";
import * as lambda from "@aws-cdk/aws-lambda";
import * as core from "@aws-cdk/core";
import * as iam from "@aws-cdk/aws-iam";

import { Stack, StackProps } from "@_org_/lib-infra-common";

export class EdgeLambdaStack extends Stack {
  constructor(scope: core.Construct, customProps: StackProps, stackProps: core.StackProps = {}) {
    super(scope, customProps, stackProps);

    const myFunc1 = new cloudfront.experimental.EdgeFunction(this, "MyFunction1", {
      runtime: lambda.Runtime.NODEJS_10_X,
      handler: "index.handler",
      code: lambda.Code.fromInline("return"),
    });
    myFunc1.currentVersion.addAlias("live");

    const myFunc2 = new cloudfront.experimental.EdgeFunction(this, "MyFunction2", {
      runtime: lambda.Runtime.NODEJS_10_X,
      handler: "index.handler",
      code: lambda.Code.fromInline("return"),
    });
    myFunc2.currentVersion.addAlias("live");
  }
}

What did you expect to happen?

Both EdgeLambda functions would be generated with unique stack/physical names.

What actually happened?

Error: There is already a Construct with name 'Aliaslive' in Stack [edge-lambda-stack-c8c09337b87f7807acc2002239aca2181ae1916d18]
    at Node.addChild (/Users/arjunnaha/Developer/_org_/web-marketing/node_modules/constructs/src/construct.ts:534:13)
    at new Node (/Users/arjunnaha/Developer/_org_/web-marketing/node_modules/constructs/src/construct.ts:75:22)
    at new ConstructNode (/Users/arjunnaha/Developer/_org_/web-marketing/node_modules/@aws-cdk/core/lib/construct-compat.ts:277:24)
    at Object.createNode (/Users/arjunnaha/Developer/_org_/web-marketing/node_modules/@aws-cdk/core/lib/construct-compat.ts:71:11)
    at new Construct (/Users/arjunnaha/Developer/_org_/web-marketing/node_modules/constructs/src/construct.ts:575:26)
    at new Construct (/Users/arjunnaha/Developer/_org_/web-marketing/node_modules/@aws-cdk/core/lib/construct-compat.ts:68:5)
    at new Resource (/Users/arjunnaha/Developer/_org_/web-marketing/node_modules/@aws-cdk/core/lib/resource.ts:116:5)
    at new FunctionBase (/Users/arjunnaha/Developer/_org_/web-marketing/node_modules/@aws-cdk/aws-lambda/lib/function-base.js:17:9)
    at new QualifiedFunctionBase (/Users/arjunnaha/Developer/_org_/web-marketing/node_modules/@aws-cdk/aws-lambda/lib/function-base.js:262:9)
    at new Alias (/Users/arjunnaha/Developer/_org_/web-marketing/node_modules/@aws-cdk/aws-lambda/lib/alias.ts:140:5)

Environment

  • CDK CLI Version: 1.90.1 (build 0aee440)
  • Framework Version: 1.90.1
  • Node.js Version: v15.5.0
  • OS: macOS Big Sur 11.2.1
  • Language (Version): TypeScript (4.1.3)

This is 🐛 Bug Report

@arjunnaha arjunnaha added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Feb 23, 2021
@github-actions github-actions bot added the @aws-cdk/aws-cloudfront Related to Amazon CloudFront label Feb 23, 2021
@github-actions github-actions bot added the @aws-cdk/aws-lambda Related to AWS Lambda label Feb 23, 2021
@arjunnaha arjunnaha changed the title (cloudfront, lambda): short issue description (cloudfront, lambda): custom EdgeFunction aliases clash Feb 23, 2021
@nija-at nija-at removed the @aws-cdk/aws-lambda Related to AWS Lambda label Feb 25, 2021
@nija-at nija-at removed their assignment Feb 25, 2021
@nija-at nija-at changed the title (cloudfront, lambda): custom EdgeFunction aliases clash (cloudfront): custom EdgeFunction aliases clash Feb 25, 2021
@njlynch njlynch added effort/small Small work item – less than a day of effort p1 and removed needs-triage This issue or PR still needs to be triaged. labels Mar 1, 2021
njlynch added a commit that referenced this issue Mar 1, 2021
Attempting to add two EdgeFunctions to the same stack, and then giving both the
same alias (e.g., 'prod', 'live') results in an ID conflict. This is because the
aliases are being added to the scope of the shared EdgeFunction stack, rather
than the scope of the Function itself.

fixes #13237
@njlynch
Copy link
Contributor

njlynch commented Mar 1, 2021

Thanks for the bug report! Fix posted for review.

@njlynch njlynch added the in-progress This issue is being actively worked on. label Mar 1, 2021
@mergify mergify bot closed this as completed in #13324 Mar 1, 2021
mergify bot pushed a commit that referenced this issue Mar 1, 2021
Attempting to add two EdgeFunctions to the same stack, and then giving both the
same alias (e.g., 'prod', 'live') results in an ID conflict. This is because the
aliases are being added to the scope of the shared EdgeFunction stack, rather
than the scope of the Function itself.

Note - Also took the opportunity to simplify one of the integ tests to deploy to a
single distribution.

fixes #13237


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

github-actions bot commented Mar 1, 2021

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

cornerwings pushed a commit to cornerwings/aws-cdk that referenced this issue Mar 8, 2021
…13324)

Attempting to add two EdgeFunctions to the same stack, and then giving both the
same alias (e.g., 'prod', 'live') results in an ID conflict. This is because the
aliases are being added to the scope of the shared EdgeFunction stack, rather
than the scope of the Function itself.

Note - Also took the opportunity to simplify one of the integ tests to deploy to a
single distribution.

fixes aws#13237


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-cloudfront Related to Amazon CloudFront bug This issue is a bug. effort/small Small work item – less than a day of effort in-progress This issue is being actively worked on. p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants