Skip to content

CloudFrontToS3: OriginAccessControl already exists #1279

@shellscape

Description

@shellscape

When using the CloudFrontToS3 construct, there's an undocumented requirement around the id constructor parameter: The inner workings of this construct will only consider 9 characters of that ID passed in. Take an identifier like this dev-svc-uploads-assets-cdn which is completely reasonable. That gets transformed into dev-s-cdn. When you're deploying more than one CDN, that ends up in an AlreadyExists error. This is due to the inner workings in the core:

The crux of this is that the function that tries to generate a unique ID doesn't follow CDK core's own algorithms, which it really should as that's one that doesn't run into conflicts.

Alternatively, we'd have properties we could provide that would override the ID generation.

At the moment, we have to use a patched dependency to get around this if we want to pass proper IDs that match our environment standards (in our case {env}-{project}-{thing name}-{thing type}

At the least, the user should know that their IDs are being squashed for resource IDs under the hood. Imagine trying to find this resource by name/id in the console and wondering where the heck it is because the ID you passed was turned into something unrecognizable.

Reproduction Steps

const result = new CloudFrontToS3(scope, 'dev-svc-uploads-assets-cdn', { ... });
const result = new CloudFrontToS3(scope, 'dev-svc-uploads-media-cdn', { ... });

Error Log

dev-svc-uploads-stack failed: Error: The stack named dev-svc-uploads-stack failed to deploy: UPDATE_ROLLBACK_COMPLETE: Resource handler returned message: "Resource of type 'AWS::CloudFront::OriginAccessControl' with identifier 'aws-cloudfront-s3-dev-s-cdn-466204b0-4968-11ef-acca-0affef817d45' already exists." (RequestToken: ecff76f4-c8bb-4910-11ed-fd67a61d9d6c, HandlerErrorCode: AlreadyExists)

Environment

  • **CDK CLI Version :2.1005.0
  • **CDK Framework Version: 2.185.0
  • **AWS Solutions Constructs Version : 2.79.1
  • **OS : Mac
  • **Language :TS

Other


This is 🐛 Bug Report

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds-triageThe issue or PR still needs to be triaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions