Skip to content

aws-cdk/aws-s3: cdk can generate an invalid lifecycle configuration for s3:Bucket #25824

@cloventt

Description

@cloventt

Describe the bug

Synthed buckets can end up with an invalid lifecycle configuration which fails to be applied by CFN when adding the expiredObjectDeleteMarker configuration.

For example, according to the CFN docs for ExpiredObjectDeleteMarker:

This cannot be specified with ExpirationInDays, ExpirationDate, or TagFilters.

However, if the developer sets expire and expiredObjectDeleteMarker, CDK synths the code with no errors.

Expected Behavior

An invalid lifecycle configuration should fail to synth.

Current Behavior

When an invalid lifecycle configuration is specified, CDK synths the artifacts without raising any warning or errors. The error only occurs when applying the template in CFN. You get this fantastically cryptic error in the CFN logs, and the stack rolls back:

The XML you provided was not well-formed or did not validate against our published schema (Service: Amazon S3; Status Code: 400; Error Code: MalformedXML;)

Reproduction Steps

This code would generate a template that would fail to be applied in CFN:

new s3.Bucket(this, 'bucket', {
      lifecycleRules: [
        {
          enabled: true,
          expiration: Duration.days(14),
          noncurrentVersionExpiration: Duration.days(7),
          abortIncompleteMultipartUploadAfter: Duration.days(1),
          expiredObjectDeleteMarker: true,
        },
      ],
    });

Possible Solution

If the user adds an invalid combination of lifecycle configurations, we could do any of these:

  • prominently warn the user that the configuration will fail in CFN
  • just fail the build completely

Additional Information/Context

No response

CDK CLI Version

2.79.1

Framework Version

No response

Node.js Version

19.1.0

OS

Linux

Language

Typescript

Language Version

4.9.5

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-s3Related to Amazon S3bugThis issue is a bug.effort/smallSmall work item – less than a day of effortgood first issueRelated to contributions. See CONTRIBUTING.mdp2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions