Skip to content

Commit 23690e4

Browse files
authored
feat(s3): adds objectSizeGreaterThan property for s3 lifecycle rule (#20425)
Fixes (first half) of #20372. This implements the `objectSizeGreaterThan` property for a S3 lifecycle rule. ---- ### All Submissions: * [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/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/master/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 f334060 commit 23690e4

File tree

6 files changed

+55
-15
lines changed

6 files changed

+55
-15
lines changed

packages/@aws-cdk/aws-s3/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@ const bucket = new s3.Bucket(this, 'MyBucket', {
576576
// the properties below are optional
577577
noncurrentVersionsToRetain: 123,
578578
}],
579+
objectSizeGreaterThan: 500,
579580
prefix: 'prefix',
580581
transitions: [{
581582
storageClass: s3.StorageClass.GLACIER,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1923,6 +1923,7 @@ export class Bucket extends BucketBase {
19231923
})),
19241924
expiredObjectDeleteMarker: rule.expiredObjectDeleteMarker,
19251925
tagFilters: self.parseTagFilters(rule.tagFilters),
1926+
objectSizeGreaterThan: rule.objectSizeGreaterThan,
19261927
};
19271928

19281929
return x;

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

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export interface LifecycleRule {
2424
* When Amazon S3 aborts a multipart upload, it deletes all parts
2525
* associated with the multipart upload.
2626
*
27-
* @default Incomplete uploads are never aborted
27+
* @default - Incomplete uploads are never aborted
2828
*/
2929
readonly abortIncompleteMultipartUploadAfter?: Duration;
3030

@@ -37,7 +37,7 @@ export interface LifecycleRule {
3737
* time unit for both properties (either in days or by date). The
3838
* expiration time must also be later than the transition time.
3939
*
40-
* @default No expiration date
40+
* @default - No expiration date
4141
*/
4242
readonly expirationDate?: Date;
4343

@@ -48,7 +48,7 @@ export interface LifecycleRule {
4848
* time unit for both properties (either in days or by date). The
4949
* expiration time must also be later than the transition time.
5050
*
51-
* @default No expiration timeout
51+
* @default - No expiration timeout
5252
*/
5353
readonly expiration?: Duration;
5454

@@ -62,7 +62,7 @@ export interface LifecycleRule {
6262
* and expiration time, the expiration time must be later than the
6363
* transition time.
6464
*
65-
* @default No noncurrent version expiration
65+
* @default - No noncurrent version expiration
6666
*/
6767
readonly noncurrentVersionExpiration?: Duration;
6868

@@ -72,7 +72,7 @@ export interface LifecycleRule {
7272
* If there are this many more noncurrent versions,
7373
* Amazon S3 permanently deletes them.
7474
*
75-
* @default No noncurrent versions to retain
75+
* @default - No noncurrent versions to retain
7676
*/
7777
readonly noncurrentVersionsToRetain?: number;
7878

@@ -93,21 +93,21 @@ export interface LifecycleRule {
9393
* time unit for both properties (either in days or by date). The
9494
* expiration time must also be later than the transition time.
9595
*
96-
* @default No transition rules
96+
* @default - No transition rules
9797
*/
9898
readonly transitions?: Transition[];
9999

100100
/**
101101
* Object key prefix that identifies one or more objects to which this rule applies.
102102
*
103-
* @default Rule applies to all objects
103+
* @default - Rule applies to all objects
104104
*/
105105
readonly prefix?: string;
106106

107107
/**
108108
* The TagFilter property type specifies tags to use to identify a subset of objects for an Amazon S3 bucket.
109109
*
110-
* @default Rule applies to all objects
110+
* @default - Rule applies to all objects
111111
*/
112112
readonly tagFilters?: {[tag: string]: any};
113113

@@ -118,6 +118,13 @@ export interface LifecycleRule {
118118
* @default false
119119
*/
120120
readonly expiredObjectDeleteMarker?: boolean;
121+
122+
/**
123+
* Specifies the minimum object size in bytes for this rule to apply to.
124+
*
125+
* @default - No rule
126+
*/
127+
readonly objectSizeGreaterThan?: number;
121128
}
122129

123130
/**
@@ -134,14 +141,14 @@ export interface Transition {
134141
*
135142
* The date value must be in ISO 8601 format. The time is always midnight UTC.
136143
*
137-
* @default No transition date.
144+
* @default - No transition date.
138145
*/
139146
readonly transitionDate?: Date;
140147

141148
/**
142149
* Indicates the number of days after creation when objects are transitioned to the specified storage class.
143150
*
144-
* @default No transition count.
151+
* @default - No transition count.
145152
*/
146153
readonly transitionAfter?: Duration;
147154
}
@@ -158,14 +165,14 @@ export interface NoncurrentVersionTransition {
158165
/**
159166
* Indicates the number of days after creation when objects are transitioned to the specified storage class.
160167
*
161-
* @default No transition count.
168+
* @default - No transition count.
162169
*/
163170
readonly transitionAfter: Duration;
164171

165172
/**
166173
* Indicates the number of noncurrent version objects to be retained. Can be up to 100 noncurrent versions retained.
167174
*
168-
* @default No noncurrent version retained.
175+
* @default - No noncurrent version retained.
169176
*/
170177
readonly noncurrentVersionsToRetain?: number;
171178
}

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@ const stack = new Stack(app, 'aws-cdk-s3');
77

88
// Test a lifecycle rule with an expiration DATE
99
new Bucket(stack, 'MyBucket', {
10-
lifecycleRules: [{
11-
expirationDate: new Date('2019-10-01'),
12-
}],
10+
lifecycleRules: [
11+
{
12+
expirationDate: new Date('2019-10-01'),
13+
},
14+
{
15+
objectSizeGreaterThan: 500,
16+
},
17+
],
1318
removalPolicy: RemovalPolicy.DESTROY,
1419
});
1520

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
{
99
"ExpirationDate": "2019-10-01T00:00:00",
1010
"Status": "Enabled"
11+
},
12+
{
13+
"ObjectSizeGreaterThan": "500",
14+
"Status": "Enabled"
1115
}
1216
]
1317
}

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,4 +291,26 @@ describe('rules', () => {
291291
},
292292
});
293293
});
294+
295+
test('Bucket with objectSizeGreaterThan', () => {
296+
// GIVEN
297+
const stack = new Stack();
298+
299+
// WHEN
300+
new Bucket(stack, 'Bucket', {
301+
lifecycleRules: [{
302+
objectSizeGreaterThan: 0,
303+
}],
304+
});
305+
306+
// THEN
307+
Template.fromStack(stack).hasResourceProperties('AWS::S3::Bucket', {
308+
LifecycleConfiguration: {
309+
Rules: [{
310+
ObjectSizeGreaterThan: 0,
311+
Status: 'Enabled',
312+
}],
313+
},
314+
});
315+
});
294316
});

0 commit comments

Comments
 (0)