Skip to content

(S3): Cannot specify number of noncurrent versions to retain in LifeCycle rule without transitioning the StorageClass #19784

@KomaGR

Description

@KomaGR

Describe the bug

Using the lifecycleRules configuration of a versioned bucket, I cannot specify how many noncurrent versions to retain without triggering any storage transition. (I want the objects to stay in STANDARD tier but that is also not available under s3.StorageClass.)

What I'm trying to achieve
I want to delete all object versions older than one day but I want to keep the five latest versions for each object (in the same storage tier). I don't want the older versions to transition to another tier since I also want to delete them after a single day if, i.e., another batch of 5 versions comes through.

Expected Behavior

The Console seems to allow exactly what I'm going after:
image

Current Behavior

Currently, the option for how many noncurrent versions to retain noncurrentVersionsToRetain is under the noncurrentVersionTransitions configuration option, which forces to specify transitionAfter and storageClass. The Console UI (see above) suggests that I would not need to specify these and only need specify noncurrentVersionExpiration.

{
    enabled: true,
    prefix: "usr_",
    noncurrentVersionExpiration: Duration.days(1),
    expiredObjectDeleteMarker: true,
    abortIncompleteMultipartUploadAfter: Duration.days(1),
    noncurrentVersionTransitions: [
        {
            transitionAfter: Duration.days(1),
            noncurrentVersionsToRetain: 5,
            storageClass: /* Side issue: There is no s3.StorageClass.STANDARD */
        }
    ]
}

Reproduction Steps

Here is the Object I'm trying to create with the noncurrentVersionTransitions config option commented out:

new s3.Bucket(this, 'bugBucket', {
            versioned: true,
            lifecycleRules: [
                {
                    enabled: true,
                    prefix: "prefix",
                    noncurrentVersionExpiration: Duration.days(1),
                    expiredObjectDeleteMarker: true,
                    abortIncompleteMultipartUploadAfter: Duration.days(1),
//                    noncurrentVersionTransitions: [
//                        {
//                            transitionAfter: Duration.days(1),
//                            noncurrentVersionsToRetain: 5,
//                            storageClass: /*  */
//                        }
//                    ]
                }
            ]
        });

Possible Solution

Judging by the UI, it looks like noncurrentVersionsToRetain should be a property of the Lifecycle rule and not nested into noncurrentVersionTransitions.

Additional Information/Context

No response

CDK CLI Version

2.19.0 (build e0d3e62)

Framework Version

aws-cdk-lib@2.8.0

Node.js Version

v16.13.2

OS

Ubuntu 20.04

Language

Typescript

Language Version

No response

Other information

No response

Metadata

Metadata

Assignees

Labels

@aws-cdk/aws-s3Related to Amazon S3effort/smallSmall work item – less than a day of effortfeature-requestA feature should be added or improved.feature/enhancementA new API to make things easier or more intuitive. A catch-all for general feature requests.good first issueRelated to contributions. See CONTRIBUTING.mdp1

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions