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

(s3): Bucket.fromBucketName crashes on valid S3 bucket name #17758

Closed
fs111 opened this issue Nov 29, 2021 · 4 comments
Closed

(s3): Bucket.fromBucketName crashes on valid S3 bucket name #17758

fs111 opened this issue Nov 29, 2021 · 4 comments
Assignees
Labels
@aws-cdk/aws-s3 Related to Amazon S3 bug This issue is a bug. needs-reproduction This issue needs reproduction. needs-triage This issue or PR still needs to be triaged. p1 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@fs111
Copy link

fs111 commented Nov 29, 2021

What is the problem?

We have a stack that uses Bucket.fromBucketName with the name of an athena results bucket. These are typically named like so "aws-athena-query-results--" and are automatically created by AWS, which is why we use the fromBucketName function. After upgrading cdk to version 1.134.0 synth started failing complainining about that bucket name:

Exception in thread "main" software.amazon.jsii.JsiiException: Invalid S3 bucket name (value: Unquoted("<redacted>"))
Bucket name must only contain lowercase characters and the symbols, period (.) and dash (-) (offset: 0)
Bucket name must start and end with a lowercase character or number (offset: 0)
Bucket name must start and end with a lowercase character or number (offset: 58)
Error: Invalid S3 bucket name (value: Unquoted("<redacted>"))
Bucket name must only contain lowercase characters and the symbols, period (.) and dash (-) (offset: 0)
Bucket name must start and end with a lowercase character or number (offset: 0)
Bucket name must start and end with a lowercase character or number (offset: 58)
    at Function.validateBucketName (/private/var/folders/j8/xm49krg57yjfzw6kzcrmn7780000gq/T/jsii-kernel-VSHQ9V/node_modules/@aws-cdk/aws-s3/lib/bucket.js:750:19)
    at Function.fromBucketAttributes (/private/var/folders/j8/xm49krg57yjfzw6kzcrmn7780000gq/T/jsii-kernel-VSHQ9V/node_modules/@aws-cdk/aws-s3/lib/bucket.js:673:16)
    at Function.fromBucketName (/private/var/folders/j8/xm49krg57yjfzw6kzcrmn7780000gq/T/jsii-kernel-VSHQ9V/node_modules/@aws-cdk/aws-s3/lib/bucket.js:654:23)
    at /private/var/folders/j8/xm49krg57yjfzw6kzcrmn7780000gq/T/jsii-java-runtime4191035261203055038/lib/program.js:8269:114
    at Kernel._wrapSandboxCode (/private/var/folders/j8/xm49krg57yjfzw6kzcrmn7780000gq/T/jsii-java-runtime4191035261203055038/lib/program.js:8860:24)
    at /private/var/folders/j8/xm49krg57yjfzw6kzcrmn7780000gq/T/jsii-java-runtime4191035261203055038/lib/program.js:8269:87
    at Kernel._ensureSync (/private/var/folders/j8/xm49krg57yjfzw6kzcrmn7780000gq/T/jsii-java-runtime4191035261203055038/lib/program.js:8841:28)
    at Kernel.sinvoke (/private/var/folders/j8/xm49krg57yjfzw6kzcrmn7780000gq/T/jsii-java-runtime4191035261203055038/lib/program.js:8269:34)
    at KernelHost.processRequest (/private/var/folders/j8/xm49krg57yjfzw6kzcrmn7780000gq/T/jsii-java-runtime4191035261203055038/lib/program.js:9757:36)
    at KernelHost.run (/private/var/folders/j8/xm49krg57yjfzw6kzcrmn7780000gq/T/jsii-java-runtime4191035261203055038/lib/program.js:9720:22)

I tried a few versions and 1.130.0 is the last that works, everything after rejects the name.

Could it be b/c the name ends in a number?

Reproduction Steps

Bucket.fromBucketName(this, "myBucket", "aws-athena-query-results-123456789-us-east-2")

What did you expect to happen?

It uses the bucket.

What actually happened?

Exception in thread "main" software.amazon.jsii.JsiiException: Invalid S3 bucket name (value: Unquoted("<redacted>"))
Bucket name must only contain lowercase characters and the symbols, period (.) and dash (-) (offset: 0)
Bucket name must start and end with a lowercase character or number (offset: 0)
Bucket name must start and end with a lowercase character or number (offset: 58)
Error: Invalid S3 bucket name (value: Unquoted("<redacted>"))
Bucket name must only contain lowercase characters and the symbols, period (.) and dash (-) (offset: 0)
Bucket name must start and end with a lowercase character or number (offset: 0)
Bucket name must start and end with a lowercase character or number (offset: 58)
    at Function.validateBucketName (/private/var/folders/j8/xm49krg57yjfzw6kzcrmn7780000gq/T/jsii-kernel-VSHQ9V/node_modules/@aws-cdk/aws-s3/lib/bucket.js:750:19)
    at Function.fromBucketAttributes (/private/var/folders/j8/xm49krg57yjfzw6kzcrmn7780000gq/T/jsii-kernel-VSHQ9V/node_modules/@aws-cdk/aws-s3/lib/bucket.js:673:16)
    at Function.fromBucketName (/private/var/folders/j8/xm49krg57yjfzw6kzcrmn7780000gq/T/jsii-kernel-VSHQ9V/node_modules/@aws-cdk/aws-s3/lib/bucket.js:654:23)
    at /private/var/folders/j8/xm49krg57yjfzw6kzcrmn7780000gq/T/jsii-java-runtime4191035261203055038/lib/program.js:8269:114
    at Kernel._wrapSandboxCode (/private/var/folders/j8/xm49krg57yjfzw6kzcrmn7780000gq/T/jsii-java-runtime4191035261203055038/lib/program.js:8860:24)
    at /private/var/folders/j8/xm49krg57yjfzw6kzcrmn7780000gq/T/jsii-java-runtime4191035261203055038/lib/program.js:8269:87
    at Kernel._ensureSync (/private/var/folders/j8/xm49krg57yjfzw6kzcrmn7780000gq/T/jsii-java-runtime4191035261203055038/lib/program.js:8841:28)
    at Kernel.sinvoke (/private/var/folders/j8/xm49krg57yjfzw6kzcrmn7780000gq/T/jsii-java-runtime4191035261203055038/lib/program.js:8269:34)
    at KernelHost.processRequest (/private/var/folders/j8/xm49krg57yjfzw6kzcrmn7780000gq/T/jsii-java-runtime4191035261203055038/lib/program.js:9757:36)
    at KernelHost.run (/private/var/folders/j8/xm49krg57yjfzw6kzcrmn7780000gq/T/jsii-java-runtime4191035261203055038/lib/program.js:9720:22)

CDK CLI Version

1.134.0 (build dd5e12d)

Framework Version

1.134

Node.js Version

v14.17.6

OS

Darwin 19.6.0 Darwin Kernel Version 19.6.0: Tue Oct 12 18:34:05 PDT 2021; root:xnu-6153.141.43~1/RELEASE_X86_64

Language

Java

Language Version

Java 11

Other information

No response

@fs111 fs111 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 29, 2021
@github-actions github-actions bot added the @aws-cdk/aws-s3 Related to Amazon S3 label Nov 29, 2021
@peterwoodworth
Copy link
Contributor

@otaviomacedo looks like #16915 broke bucket imports in some cases

@ryparker
Copy link
Contributor

ryparker commented Nov 29, 2021

Hey @fs111 👋🏻 Thanks for bringing this to our attention.

I'm not able to reproduce this. Could you review the following and let me know if i'm missing anything?

I created a bucket with the name aws-athena-query-results-123456789-us-east-2, then tried to import using CDK's .fromBucketName().

https://github.com/ryparker/aws-cdk-sample-s3-import/blob/4ca8afd62acba87acd3b9f23db88743c0ed7367b/src/main/java/com/myorg/AwsCdkSampleS3ImportStack.java#L17-L26

    public AwsCdkSampleS3ImportStack(final Construct scope, final String id, final StackProps props) {
        super(scope, id, props);

        @NotNull IBucket bucket = Bucket.fromBucketName(this, "myBucket", "aws-athena-query-results-123456789-us-east-2");

        CfnOutput.Builder.create(this, "Bucket")
          .description("Bucket Name")
          .value(bucket.getBucketName())
          .build();
    }

Ran the following without error using Java@v11.0.13 CDK@v1.34.0 Node@v16.13.0 and v14.17.6:

  1. mvn package
  2. cdk synth
  3. cdk deploy --all

Full app is available here.


I also tested this with a Typescript app, same result: https://github.com/ryparker/aws-cdk-sample-s3-import

@ryparker ryparker added needs-reproduction This issue needs reproduction. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. p1 labels Nov 29, 2021
@fs111
Copy link
Author

fs111 commented Nov 30, 2021

@ryparker thanks for looking into it. I found the issue. The problem was at my end after all. We had a bug in code that was reading the bucket name from a config file (that is where that Unquoted("...") comes from). Up until 1.130 it passed the CDK. The new stricter code caught the bug.

Sorry for the noise. PEBKAC.

@fs111 fs111 closed this as completed Nov 30, 2021
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-s3 Related to Amazon S3 bug This issue is a bug. needs-reproduction This issue needs reproduction. needs-triage This issue or PR still needs to be triaged. p1 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

4 participants