Skip to content

Commit b20a6b4

Browse files
authored
fix(s3): remove restriction of creating lifecycle rule for noncurrent objects when bucket versionining is not set up (#22803)
fixes #22392 ---- ### All Submissions: * [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [x] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent ddee5cf commit b20a6b4

File tree

9 files changed

+12
-53
lines changed

9 files changed

+12
-53
lines changed

packages/@aws-cdk/aws-s3/lib/bucket.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1766,7 +1766,6 @@ export class Bucket extends BucketBase {
17661766
protected disallowPublicAccess?: boolean;
17671767
private accessControl?: BucketAccessControl;
17681768
private readonly lifecycleRules: LifecycleRule[] = [];
1769-
private readonly versioned?: boolean;
17701769
private readonly eventBridgeEnabled?: boolean;
17711770
private readonly metrics: BucketMetrics[] = [];
17721771
private readonly cors: CorsRule[] = [];
@@ -1807,7 +1806,6 @@ export class Bucket extends BucketBase {
18071806

18081807
resource.applyRemovalPolicy(props.removalPolicy);
18091808

1810-
this.versioned = props.versioned;
18111809
this.encryptionKey = encryptionKey;
18121810
this.eventBridgeEnabled = props.eventBridgeEnabled;
18131811

@@ -1872,12 +1870,6 @@ export class Bucket extends BucketBase {
18721870
* @param rule The rule to add
18731871
*/
18741872
public addLifecycleRule(rule: LifecycleRule) {
1875-
if ((rule.noncurrentVersionExpiration !== undefined
1876-
|| (rule.noncurrentVersionTransitions && rule.noncurrentVersionTransitions.length > 0))
1877-
&& !this.versioned) {
1878-
throw new Error("Cannot use 'noncurrent' rules on a nonversioned bucket");
1879-
}
1880-
18811873
this.lifecycleRules.push(rule);
18821874
}
18831875

packages/@aws-cdk/aws-s3/test/integ.lifecycle-expiration.js.snapshot/aws-cdk-s3.assets.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
2-
"version": "20.0.0",
2+
"version": "21.0.0",
33
"files": {
4-
"679bf529d9a3ed82ef264cdba57192bff86674a9ce36d45db3ec5c344ae364c0": {
4+
"928a24cbf7a16b7c4d15a9ceca38a2f7f016495b93db9bdf0160accc3d13876c": {
55
"source": {
66
"path": "aws-cdk-s3.template.json",
77
"packaging": "file"
88
},
99
"destinations": {
1010
"current_account-current_region": {
1111
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
12-
"objectKey": "679bf529d9a3ed82ef264cdba57192bff86674a9ce36d45db3ec5c344ae364c0.json",
12+
"objectKey": "928a24cbf7a16b7c4d15a9ceca38a2f7f016495b93db9bdf0160accc3d13876c.json",
1313
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
1414
}
1515
}

packages/@aws-cdk/aws-s3/test/integ.lifecycle-expiration.js.snapshot/aws-cdk-s3.template.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
"Status": "Enabled"
1414
}
1515
]
16-
},
17-
"VersioningConfiguration": {
18-
"Status": "Enabled"
1916
}
2017
},
2118
"UpdateReplacePolicy": "Retain",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"version":"20.0.0"}
1+
{"version":"21.0.0"}

packages/@aws-cdk/aws-s3/test/integ.lifecycle-expiration.js.snapshot/integ.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "20.0.0",
2+
"version": "21.0.0",
33
"testCases": {
44
"integ.lifecycle-expiration": {
55
"stacks": [

packages/@aws-cdk/aws-s3/test/integ.lifecycle-expiration.js.snapshot/manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "20.0.0",
2+
"version": "21.0.0",
33
"artifacts": {
44
"Tree": {
55
"type": "cdk:tree",
@@ -23,7 +23,7 @@
2323
"validateOnSynth": false,
2424
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
2525
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
26-
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/679bf529d9a3ed82ef264cdba57192bff86674a9ce36d45db3ec5c344ae364c0.json",
26+
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/928a24cbf7a16b7c4d15a9ceca38a2f7f016495b93db9bdf0160accc3d13876c.json",
2727
"requiresBootstrapStackVersion": 6,
2828
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
2929
"additionalDependencies": [

packages/@aws-cdk/aws-s3/test/integ.lifecycle-expiration.js.snapshot/tree.json

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"path": "Tree",
1010
"constructInfo": {
1111
"fqn": "constructs.Construct",
12-
"version": "10.1.85"
12+
"version": "10.1.140"
1313
}
1414
},
1515
"aws-cdk-s3": {
@@ -36,9 +36,6 @@
3636
"status": "Enabled"
3737
}
3838
]
39-
},
40-
"versioningConfiguration": {
41-
"status": "Enabled"
4239
}
4340
}
4441
},
@@ -55,14 +52,14 @@
5552
}
5653
},
5754
"constructInfo": {
58-
"fqn": "constructs.Construct",
59-
"version": "10.1.85"
55+
"fqn": "@aws-cdk/core.Stack",
56+
"version": "0.0.0"
6057
}
6158
}
6259
},
6360
"constructInfo": {
64-
"fqn": "constructs.Construct",
65-
"version": "10.1.85"
61+
"fqn": "@aws-cdk/core.App",
62+
"version": "0.0.0"
6663
}
6764
}
6865
}

packages/@aws-cdk/aws-s3/test/integ.lifecycle-expiration.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ new Bucket(stack, 'MyBucket', {
1010
noncurrentVersionExpiration: Duration.days(30),
1111
noncurrentVersionsToRetain: 123,
1212
}],
13-
versioned: true,
1413
});
1514

1615
app.synth();

packages/@aws-cdk/aws-s3/test/rules.test.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -96,28 +96,6 @@ describe('rules', () => {
9696
});
9797
});
9898

99-
test('Noncurrent rule on nonversioned bucket fails', () => {
100-
// GIVEN
101-
const stack = new Stack();
102-
103-
// WHEN: Fail because of lack of versioning
104-
expect(() => {
105-
new Bucket(stack, 'Bucket1', {
106-
lifecycleRules: [{
107-
noncurrentVersionExpiration: Duration.days(10),
108-
}],
109-
});
110-
}).toThrow();
111-
112-
// WHEN: Succeeds because versioning is enabled
113-
new Bucket(stack, 'Bucket2', {
114-
versioned: true,
115-
lifecycleRules: [{
116-
noncurrentVersionExpiration: Duration.days(10),
117-
}],
118-
});
119-
});
120-
12199
test('Bucket with expiredObjectDeleteMarker', () => {
122100
// GIVEN
123101
const stack = new Stack();
@@ -146,7 +124,6 @@ describe('rules', () => {
146124

147125
// WHEN: Noncurrent version to retain available
148126
new Bucket(stack, 'Bucket1', {
149-
versioned: true,
150127
lifecycleRules: [{
151128
noncurrentVersionExpiration: Duration.days(10),
152129
noncurrentVersionTransitions: [
@@ -185,7 +162,6 @@ describe('rules', () => {
185162

186163
// WHEN: Noncurrent version to retain not set
187164
new Bucket(stack, 'Bucket1', {
188-
versioned: true,
189165
lifecycleRules: [{
190166
noncurrentVersionExpiration: Duration.days(10),
191167
noncurrentVersionTransitions: [
@@ -222,7 +198,6 @@ describe('rules', () => {
222198

223199
// WHEN: Noncurrent version to retain available
224200
new Bucket(stack, 'Bucket1', {
225-
versioned: true,
226201
lifecycleRules: [{
227202
noncurrentVersionExpiration: Duration.days(10),
228203
noncurrentVersionsToRetain: 1,
@@ -261,7 +236,6 @@ describe('rules', () => {
261236

262237
// WHEN: Noncurrent version to retain not set
263238
new Bucket(stack, 'Bucket1', {
264-
versioned: true,
265239
lifecycleRules: [{
266240
noncurrentVersionExpiration: Duration.days(10),
267241
noncurrentVersionTransitions: [

0 commit comments

Comments
 (0)