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): LifecycleRule builder allows invalid mix of parameters #18924

Open
tbenbrahim opened this issue Feb 10, 2022 · 0 comments
Open

(S3): LifecycleRule builder allows invalid mix of parameters #18924

tbenbrahim opened this issue Feb 10, 2022 · 0 comments
Labels
@aws-cdk/aws-s3 Related to Amazon S3 bug This issue is a bug. p2

Comments

@tbenbrahim
Copy link

tbenbrahim commented Feb 10, 2022

What is the problem?

I created the lifecycle rule shown below and assigned it to an S3 bucket:

    LifecycleRule deleteAfterThirtyDays = LifecycleRule.builder()
        .id("deleteAtThirtyDays")
        .abortIncompleteMultipartUploadAfter(Duration.days(1))
        .expiration(Duration.days(30))
        .expiredObjectDeleteMarker(true)
        .enabled(true)
        .build();

This lifecycle rule is invalid, because, during deployment, the following cryptic error is returned from the S3 service:

The XML you provided was not well-formed or did not validate against our published schema

This was fixed after modifying the lifecyle rule to:

    LifecycleRule deleteAfterThirtyDays = LifecycleRule.builder()
        .expiration(Duration.days(30))
        .enabled(true)
        .build();

Reproduction Steps

public class BootstrapStack extends Stack {

  public BootstrapStack(final Construct scope, final String id) {
    this(scope, id, null);
  }

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

    LifecycleRule deleteAfterThirtyDays = LifecycleRule.builder()
        .id("deleteAtThirtyDays")
        .abortIncompleteMultipartUploadAfter(Duration.days(1))
        .expiration(Duration.days(30))
        .expiredObjectDeleteMarker(true)
        .enabled(true)
        .build();
    Bucket loggingBucket = Bucket.Builder.create(this, "LoggingBucket")
        .bucketName(Fn.sub("com.acme.myapp.logs.${AWS::AccountId}"))
        .blockPublicAccess(BlockPublicAccess.BLOCK_ALL)
        .encryption(BucketEncryption.S3_MANAGED)
        .lifecycleRules(Collections.singletonList(deleteAfterThirtyDays))
        .removalPolicy(RemovalPolicy.RETAIN)
        .build();
  }
}

What did you expect to happen?

I would expect the build() call in the LifecycleRuleBuilder to detect an invalid combination of parameters and to throw a clear error during the synth phase, otherwise I do not see how CDK is any more helpful than yaml.

What actually happened?

During deployment, the following cryptic error is returned from the S3 service:

The XML you provided was not well-formed or did not validate against our published schema

CDK CLI Version

2.12.0 (build c9786db)

Framework Version

v2

Node.js Version

v14.17.1

OS

Windows 10 Enterprise

Language

Java

Language Version

Coretto 11.0.11.9

Other information

No response

@tbenbrahim tbenbrahim added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Feb 10, 2022
@github-actions github-actions bot added the @aws-cdk/aws-s3 Related to Amazon S3 label Feb 10, 2022
@NGL321 NGL321 added p2 and removed needs-triage This issue or PR still needs to be triaged. labels Feb 14, 2022
@aws aws deleted a comment from github-actions bot Jan 27, 2023
@comcalvi comcalvi reopened this Jan 27, 2023
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. p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants