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]: migrating cloudfrontWebDistribution to Distribution #32373

Closed
1 task
santiagovj22 opened this issue Dec 3, 2024 · 4 comments
Closed
1 task
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 p3

Comments

@santiagovj22
Copy link

santiagovj22 commented Dec 3, 2024

Describe the bug

i am migrating from cloudfrontWebDistribution to Distribution.

before:

  const logicalIdcloudfrontDist = genLogicalId(scopeId, 'webDist')
  const cfDistribution: aws_cloudfront.CloudFrontWebDistribution = new aws_cloudfront.CloudFrontWebDistribution(
    scope,
    logicalIdcloudfrontDist,
    defaultProps
  )

after:

  const logicalIdcloudfrontDist = genLogicalId(scopeId, 'webDist')
  const cfDistribution: aws_cloudfront.Distribution = new aws_cloudfront.Distribution(
    scope,
    logicalIdcloudfrontDist,
    defaultProps
  )

then got this error:

| 8:27:58 AM | CREATE_FAILED | AWS::CloudFront::Distribution | CoreInfra/AppTier/CFNDist0/webDist (webDist) Resource handler returned message: "Invalid request provided: AWS::CloudFront::Distribution: One or more of the CNAMEs you provided are already associated with a different resource. (Service: CloudFront, Status Code: 409, Request ID: 103a9d3c-7f66-4b54-bc1c-9ea13f3cc799)" (RequestToken: d276c6f3-5447-4bec-0bb7-5a761708a076, HandlerErrorCode: InvalidRequest)`

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

after possibles workarounds none of them work:

   const cfnDistribution = cfDistribution.node.defaultChild as aws_cloudfront.CfnDistribution
   cfnDistribution.overrideLogicalId(logicalIdcloudfrontDist)

neither

 const cfnDistribution = cfDistribution.node.defaultChild as CfnElement
  cfnDistribution.node.id = logicalIdcloudfrontDist

due to:

Cannot assign to 'id' because it is a read-only property.ts(2540)
(property) Node.id: any
The id of this construct within the current scope.

This is a a scope-unique id. To obtain an app-unique id for this construct, use uniqueId.

@stability — stable

what should i do in this case? i have many cloudfrontDistributions already deployed using aws_cloudfront.cloudfrontWebDistribution but i have to migrate to aws_cloudfront.Distribution to use some features such as responseHeaderPolicy

i need to keep the old logicalId and reuse to the distribution

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Version

"aws-cdk": "2.97.1",     "aws-cdk-lib": "2.97.1",

Expected Behavior

deploy without issues

Current Behavior

stopped by this error

Reproduction Steps

migrating from cloudfrontWebDistribution to Distribution having deployed a distribution and deploy a new one with the same CNAME

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.148.1 (build 283525d)

Framework Version

No response

Node.js Version

v20.15.0

OS

windows

Language

TypeScript

Language Version

No response

Other information

No response

@santiagovj22 santiagovj22 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Dec 3, 2024
@github-actions github-actions bot added the @aws-cdk/aws-cloudfront Related to Amazon CloudFront label Dec 3, 2024
@santiagovj22 santiagovj22 changed the title (cloudfront): (migrating cloudfrontWebDistribution to Distribution) [cloudfront]: migrating cloudfrontWebDistribution to Distribution Dec 3, 2024
@pahud pahud self-assigned this Dec 9, 2024
@pahud
Copy link
Contributor

pahud commented Dec 9, 2024

migrating cloudfrontWebDistribution to Distribution

If you need to migrate from cloudfrontWebDistribution to Distribution

  1. you need to find out the logicalId of cloudfrontWebDistribution
  2. create a new Distribution and override its logicalId using overrideLogicalId
  3. run cdk diff make sure the existing distribution will not update any property that requires "resource replacement" as this will trigger CFN to create a new distribution which might conflict the existing one.
  4. as long as the override would not update any properties it should work as expected.

@pahud pahud added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. p3 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 Dec 9, 2024
@pahud pahud removed their assignment Dec 9, 2024
Copy link

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Dec 11, 2024
@santiagovj22
Copy link
Author

Hi @pahud Thanks for your answer.

i did a wrokaround that i saw related to this issue:

Issue

this worked for me as scalable solution for hundreds distributions that i im unable to have fixed the LogicalId

(<any>(cfDistribution.node.defaultChild as CfnElement).node).id = 'CFDistribution'

@github-actions github-actions bot removed closing-soon This issue will automatically close in 4 days unless further comments are made. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. labels Dec 12, 2024
Copy link

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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 p3
Projects
None yet
Development

No branches or pull requests

2 participants