question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cloudfront: How to migrate CloudFrontWebDistribution to the new Distribution class

See original GitHub issue

❓ General Issue

Please consider the following code:

new cloudfront.CloudFrontWebDistribution(this, 'CFDistribution', {
    // ...
});

I converted this into the new Distribution class.

new cloudfront.Distribution(this, 'CFDistribution', {
    // ...
});

When I deployed this new code I got the following error:

One or more of the CNAMEs you provided are already associated with a different resource. (Service: AmazonCloudFront; Status Code: 409; Error Code: CNAMEAlreadyExists;

This is because the deployment tried to create a new CloudFront distribution instead of reusing the old one.

The Question

How could I make CDK reuse the old Cloudfront distribution? Would an override of the LogicalID help here? If yes then how can it be done?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:12
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
hanazukicommented, Apr 21, 2021

FWIW, the following change works for me.

-    const distribution = new cloudfront.CloudFrontWebDistribution(this, 'Distribution', {
-      // ...
-    });
+    const distribution = new cloudfront.Distribution(this, 'Distribution', {
+      // ...
+    });

+    (distribution.node.defaultChild as cloudfront.CfnDistribution).overrideLogicalId('DistributionCFDistributionXXXXXXXX');

where the logicalId comes from my existing stack. Check cdk diff to make sure the distribution is reused.

0reactions
caevvcommented, Oct 25, 2022

I can’t see that being scalable or possible when you have hundreds of environments being deployed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

class CloudFrontWebDistribution (construct) · AWS CDK
Unique identifier that specifies the AWS WAF web ACL to associate with this CloudFront distribution. To specify a web ACL created using the...
Read more >
How to migrate from one cloudfront distribution to another
Create the new distribution with the correct certificate but no Alternate Domain Name, and allow it to stabilize. Change the DNS for the...
Read more >
CloudFront — Boto3 Docs 1.26.35 documentation
With this operation you can move an alias that's already in use on a CloudFront distribution to a different distribution in one step....
Read more >
aws-cdk.aws-cloudfront - PyPI
CloudFront distributions deliver your content from one or more origins; an origin is the ... Replace new CloudFrontWebDistribution with new Distribution .
Read more >
AWS AMER Summit Aug 2021: Migrating content ... - YouTube
In this session, learn how to migrate your content delivery ... AMER Summit Aug 2021: Migrating content distribution to Amazon CloudFront : ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found