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

Replacing custom paths results in CFN update error #2

Open
ssennettau opened this issue Feb 25, 2024 · 2 comments
Open

Replacing custom paths results in CFN update error #2

ssennettau opened this issue Feb 25, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@ssennettau
Copy link
Owner

ssennettau commented Feb 25, 2024

🤔 Expected Behaviour

After creating a CDK Stack using the CloudFrontRedirector Construct which includes customPaths, I should be able to modify the contents to different paths, or new paths, and to have it take effect without any issue.

💥 Actual Behaviour

When custom paths are modified, it triggers an update of the resource. The KeyValueStore returns an error

x:xx:xx xM | UPDATE_FAILED        | AWS::CloudFront::KeyValueStore                  | RedirectionForWebsiteRedirectMapA33E06EB
CloudFormation cannot update a stack when a custom-named resource requires replacing. Rename [StackName][ResourceName]RedirectMap[UniqueID] and update the stack again.

🛠️ Steps to Reproduce

  1. Create a new CDK Stack
  2. Add the following resource
const redirect = new RedirectionSite(this, "RedirectForWebsite", {
      targetUrl: "https://github.com/ssennettau/CloudFrontRedirector-Construct",
      pathRedirects: [
        {
          path: "/repo",
          destination: "https://github.com/ssennettau/CloudFrontRedirector"
        }
      ]
    });
  1. Deploy the CDK stack
  2. Modify a customPath
const redirect = new RedirectionSite(this, "RedirectForWebsite", {
      targetUrl: "https://github.com/ssennettau/CloudFrontRedirector-Construct",
      pathRedirects: [
        {
          path: "/repository",
          destination: "https://github.com/ssennettau/CloudFrontRedirector-Construct"
        }
      ]
    });
  1. Attempt to deploy the CDK stack again

Error as described in Actual Behaviour should be present.

💡 Workaround (if known)

Renaming the resource is an effective, though inefficient way to bypass this bug.

const redirect = new RedirectionSite(this, "RedirectForWebsite", { ... });

// ...renamed...

const redirect = new RedirectionSite(this, "RedirectForWebsite-2", { ... });

This also triggers a full deletion and re-creation of the whole underlying construct, including the CloudFront Distribution, and any Route 53 records. They're all re-created, but this can take over 15 minutes for the deployment to complete.

@ssennettau ssennettau self-assigned this Feb 25, 2024
@ssennettau ssennettau added the bug Something isn't working label Feb 25, 2024
@ssennettau
Copy link
Owner Author

Issue is with how the underlying cloudfront.KeyValueStore works.

The contents of the KeyValueStore are derived from an S3 Object, and aren't stored in the resource itself. Since the underlying L2 construct doesn't support in-line declarations aws-cdk issue #29204, the adopted workaround for this construct creates a temporary file to be uploaded to S3 using the cloudfront.ImportSource.fromAsset method.

This behaviour confirmed in a blog post found, AWS CDK now supports L2 Construct for CloudFront KeyValueStore (title translated).

This might be solved by keeping the file in a static bucket location, which can be modified with the new contents, but it should probably be fixed in the CDK Construct itself. Will investigate further when time permits.

@ssennettau
Copy link
Owner Author

Implemented workaround patch (PR #3) for the issue by the construct automatically randomizing the name of the KeyValueStore each time. Solves the user experience issue, but leaves the problem that it updates the underlying CloudFront Distribution each time, taking extra time to deploy.

Leaving open for additional work and reference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant