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): Lamda@Edge synth fails with newStyleStackSynthesis #12172

Closed
jumi-dev opened this issue Dec 20, 2020 · 1 comment · Fixed by #12356
Closed

(cloudfront): Lamda@Edge synth fails with newStyleStackSynthesis #12172

jumi-dev opened this issue Dec 20, 2020 · 1 comment · Fixed by #12356
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 p1

Comments

@jumi-dev
Copy link
Contributor

If newStyleStackSynthesis is enabled in a CDK stack and the stack uses a Lamda@Edge function, the synth-action leads to an error: Cannot add assets to a Stack that uses the BootstraplessSynthesizer

Reproduction Steps

Create a new CDK project and enable newStyleStackSynthesis in cdk.json by adding "@aws-cdk/core:newStyleStackSynthesis": true.

Add a Lambda@Edge function to the new stack as described in the documentation:

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

    const myFunc = new cloudfront.experimental.EdgeFunction(this, 'MyFunction', {
      runtime: lambda.Runtime.NODEJS_10_X,
      handler: 'index.handler',
      code: lambda.Code.fromAsset(path.join(__dirname, 'lambda-handler')),
    });
    
  }
}

Set the region to a value which is different to us-east-1.

Execute cdk synth.

What did you expect to happen?

CDK stack should be synthesized successfully.

What actually happened?

Error message appears:
Cannot add assets to a Stack that uses the BootstraplessSynthesizer

Environment

  • **CDK CLI Version : 1.79.0
  • **Framework Version: 1.79.0
  • **Node.js Version: v12.18.3
  • **OS : macOS 10.15.7
  • **Language (Version): TypeScript (4.0.2)

Other

In class edge-function.ts, the method crossRegionSupportSynthesizer returns the BootstraplessSynthesizer.
For testing, I replaced

new BootstraplessSynthesizer({
  deployRoleArn: scopeStackSynthesizer.deployRoleArn,
  cloudFormationExecutionRoleArn: scopeStackSynthesizer.cloudFormationExecutionRoleArn,
})

with

new DefaultStackSynthesizer()

After doing this change, I could deploy my stack and the edge-lambda-stack successfully. Is this the correct fix for the issue?


This is 🐛 Bug Report

@jumi-dev jumi-dev added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Dec 20, 2020
@github-actions github-actions bot added the @aws-cdk/aws-cloudfront Related to Amazon CloudFront label Dec 20, 2020
njlynch added a commit that referenced this issue Jan 5, 2021
The EdgeFunction construct copied some patterns from CodePipelines to enable
cross-environment interaction. One key difference is that for Lambda@Edge,
CDK assets are created in the cross-environment support stack. This isn't
supported by the BootstraplessSynthesizer, so this custom logic (copied from
CodePipelines) needs to be removed.

The EdgeFunction support stack will now use whatever synthesizer is default for
the current stack.

fixes #12172
njlynch added a commit that referenced this issue Jan 5, 2021
The EdgeFunction construct copied some patterns from CodePipelines to enable
cross-environment interaction. One key difference is that for Lambda@Edge,
CDK assets are created in the cross-environment support stack. This isn't
supported by the BootstraplessSynthesizer, so this custom logic (copied from
CodePipelines) needs to be removed.

The EdgeFunction support stack will now use whatever synthesizer is default for
the current stack.

fixes #12172
@njlynch njlynch added p1 effort/small Small work item – less than a day of effort and removed needs-triage This issue or PR still needs to be triaged. labels Jan 5, 2021
@mergify mergify bot closed this as completed in #12356 Jan 5, 2021
mergify bot pushed a commit that referenced this issue Jan 5, 2021
The `EdgeFunction` construct copied some patterns from CodePipelines to enable
cross-environment interaction. One key difference is that for Lambda@Edge,
CDK assets are created in the cross-environment support stack. This isn't
supported by the BootstraplessSynthesizer, so this custom logic (copied from
CodePipelines) needs to be removed.

The EdgeFunction support stack will now use whatever synthesizer is default for
the current stack.

fixes #12172


----

*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 Jan 5, 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.

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 p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants