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

fix(s3): remove restriction of creating lifecycle rule for noncurrent objects when bucket versionining is not set up #22803

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions packages/@aws-cdk/aws-s3/lib/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1766,7 +1766,6 @@ export class Bucket extends BucketBase {
protected disallowPublicAccess?: boolean;
private accessControl?: BucketAccessControl;
private readonly lifecycleRules: LifecycleRule[] = [];
private readonly versioned?: boolean;
private readonly eventBridgeEnabled?: boolean;
private readonly metrics: BucketMetrics[] = [];
private readonly cors: CorsRule[] = [];
Expand Down Expand Up @@ -1807,7 +1806,6 @@ export class Bucket extends BucketBase {

resource.applyRemovalPolicy(props.removalPolicy);

this.versioned = props.versioned;
this.encryptionKey = encryptionKey;
this.eventBridgeEnabled = props.eventBridgeEnabled;

Expand Down Expand Up @@ -1872,12 +1870,6 @@ export class Bucket extends BucketBase {
* @param rule The rule to add
*/
public addLifecycleRule(rule: LifecycleRule) {
if ((rule.noncurrentVersionExpiration !== undefined
|| (rule.noncurrentVersionTransitions && rule.noncurrentVersionTransitions.length > 0))
&& !this.versioned) {
throw new Error("Cannot use 'noncurrent' rules on a nonversioned bucket");
}

this.lifecycleRules.push(rule);
}

Expand Down
22 changes: 0 additions & 22 deletions packages/@aws-cdk/aws-s3/test/rules.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,28 +96,6 @@ describe('rules', () => {
});
});

test('Noncurrent rule on nonversioned bucket fails', () => {
// GIVEN
const stack = new Stack();

// WHEN: Fail because of lack of versioning
expect(() => {
new Bucket(stack, 'Bucket1', {
lifecycleRules: [{
noncurrentVersionExpiration: Duration.days(10),
}],
});
}).toThrow();

// WHEN: Succeeds because versioning is enabled
new Bucket(stack, 'Bucket2', {
versioned: true,
lifecycleRules: [{
noncurrentVersionExpiration: Duration.days(10),
}],
});
});

test('Bucket with expiredObjectDeleteMarker', () => {
// GIVEN
const stack = new Stack();
Expand Down