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

aws-s3: Unable to use Bucket.fromBucketName on legacy s3 bucket with Uppcase Letters in the name #31731

Closed
1 task
gregmagdits opened this issue Oct 11, 2024 · 6 comments · Fixed by #31813
Closed
1 task
Assignees
Labels
@aws-cdk/aws-s3 Related to Amazon S3 bug This issue is a bug. effort/medium Medium work item – several days of effort p2

Comments

@gregmagdits
Copy link

Describe the bug

I'm attempting to reference an s3 bucket in my cdk code that was created in 2013 outside of cdk. The bucket has Capital letters in its name, which was legal for buckets before March 1, 2018 (new buckets can't have Capital letters or underscores in their names). I've tried referencing the bucket with both Bucket.fromBucketName and Bucket.fromBucketAttributes, but both throw this error:
(note that I've slightly changed the name of the actual bucket for privacy)

Error: Invalid S3 bucket name (value: ABCD_Central_1)
Bucket name must only contain lowercase characters and the symbols, period (.), underscore (_), and dash (-) (offset: 0)
Bucket name must start and end with a lowercase character or number (offset: 0)
at Function.validateBucketName (cdk-bug-test/node_modules/aws-cdk-lib/aws-s3/lib/bucket.js:1:19752)
at Function.fromBucketAttributes (cdk-bug-test/node_modules/aws-cdk-lib/aws-s3/lib/bucket.js:1:15111)
at Function.fromBucketName (cdk-bug-test/node_modules/aws-cdk-lib/aws-s3/lib/bucket.js:1:14511)

Regression Issue

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

Last Known Working CDK Version

No response

Expected Behavior

I expect to be able to import the bucket.

Current Behavior

See error message in the description

Reproduction Steps

import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';

export class CdkBugTestStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);
    //
    let bucket = cdk.aws_s3.Bucket.fromBucketName(this, 'test-bucket', 'ABCD_Central_1');
    // also didnt work
    //let fromBucketName = cdk.aws_s3.Bucket.fromBucketArn(this, 'test-bucket', 'arn:aws:s3:::ABCD_Central_1');
    /*let fromBucketName = cdk.aws_s3.Bucket.fromBucketAttributes(this, 'test-bucket', {
      bucketName: 'NDAR_Central_1'
    });*/
  }
}

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.161.1

Framework Version

No response

Node.js Version

v20.15.0

OS

Ubuntu via (Window Subsystem for Linux)

Language

TypeScript

Language Version

No response

Other information

No response

@gregmagdits gregmagdits added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 11, 2024
@github-actions github-actions bot added the @aws-cdk/aws-s3 Related to Amazon S3 label Oct 11, 2024
@gregmagdits
Copy link
Author

Note - this is almost identical to #22640

@khushail khushail added investigating This issue is being investigated and/or work is in progress to resolve the issue. and removed needs-triage This issue or PR still needs to be triaged. labels Oct 11, 2024
@khushail khushail self-assigned this Oct 11, 2024
@khushail khushail added the p2 label Oct 11, 2024
@khushail
Copy link
Contributor

@gregmagdits , thanks for reaching out and linking similar issue.

As mentioned in the linked issue and also on the S3 README-

Note that this method allows importing buckets with legacy names containing underscores (_), which was permitted for buckets created before March 1, 2018. For buckets created after this date, underscores are not allowed in the bucket name.
Screenshot 2024-10-11 at 2 15 02 PM

which means your bucket name having underscore would be acceptable but I see that your bucket name consists of Uppercase letters as well which is not accepted as per norms.

You mentioned that you renamed your bucket. In that case, you might want to retry naming with lowercase letters and see if that works.

Let me know if this is not helpful.

@khushail khushail added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Oct 11, 2024
@gregmagdits
Copy link
Author

Hello @khushail ,
I think you misunderstood. In my bucket name, I only changed the first four uppercase letters to four other uppercase letters. Our bucket, created in 2013, matches the following regex.
[A-Z]{4}Central[0-9]

At one point it was definitely legal to create s3 buckets with uppercase letters. I am not sure when this policy changed (perhaps in 2018 when aws also removed the ability for bucket names to contain underscores) but the cdk should support importing buckets with capital letters in the name, if they were created at the time when that was legal. The cdk already makes this provision for underscores, so it would just need to expand on this logic to include uppercase letters.

Please let me know if more information is needed. We do have an aws support account so if you need the name of the bucket, I would be happy to open a support ticket and reference this github issue.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Oct 13, 2024
@khushail
Copy link
Contributor

khushail commented Oct 14, 2024

@gregmagdits ,thanks for elaborating on your usecase. However I am not really sure if CDK Team would support such a case.

I would be reaching out to core team and would request their insights on this issue whether it should be supported(Uppercase naming support for Buckets) or share any comments on this issue.
Thanks

@khushail khushail added the effort/medium Medium work item – several days of effort label Oct 14, 2024
@khushail khushail removed their assignment Oct 14, 2024
@GavinZZ
Copy link
Contributor

GavinZZ commented Oct 16, 2024

Yes, you're right. The support of upper case letters in bucket name is removed since 2018, see https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html. Before March 1, 2018, buckets created in the US East (N. Virginia) Region could have names that were up to 255 characters long and included uppercase letters and underscores. Beginning March 1, 2018, new buckets in US East (N. Virginia) must conform to the same rules applied in all other Regions..

The current implementation of fromBucketAttributes method set allowLegacyBucketNaming to true. We should also allow upper case values when allowLegacyBucketNaming is set to true.

@5d 5d self-assigned this Oct 18, 2024
@mergify mergify bot closed this as completed in #31813 Oct 21, 2024
mergify bot pushed a commit that referenced this issue Oct 21, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
…31813)

### Issue # (if applicable)

Closes #31731

### Reason for this change



As @GavinZZ [commented](#31731 (comment)) in issue #31731, the official AWS S3 documentation stated that uppercase characters were permitted in bucket names prior to March 1, 2018.

### Description of changes


- add support for uppercase characters in legacy bucket names

### Description of how you validated changes



- added new unit test cases and updated the integration test cases with legacy bucket names

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
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 Oct 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
@aws-cdk/aws-s3 Related to Amazon S3 bug This issue is a bug. effort/medium Medium work item – several days of effort p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants