Skip to content

Commit

Permalink
feat(s3): adds objectSizeGreaterThan property for s3 lifecycle rule (#…
Browse files Browse the repository at this point in the history
…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*
  • Loading branch information
daschaa authored May 25, 2022
1 parent f334060 commit 23690e4
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 15 deletions.
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-s3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@ const bucket = new s3.Bucket(this, 'MyBucket', {
// the properties below are optional
noncurrentVersionsToRetain: 123,
}],
objectSizeGreaterThan: 500,
prefix: 'prefix',
transitions: [{
storageClass: s3.StorageClass.GLACIER,
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-s3/lib/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1923,6 +1923,7 @@ export class Bucket extends BucketBase {
})),
expiredObjectDeleteMarker: rule.expiredObjectDeleteMarker,
tagFilters: self.parseTagFilters(rule.tagFilters),
objectSizeGreaterThan: rule.objectSizeGreaterThan,
};

return x;
Expand Down
31 changes: 19 additions & 12 deletions packages/@aws-cdk/aws-s3/lib/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface LifecycleRule {
* When Amazon S3 aborts a multipart upload, it deletes all parts
* associated with the multipart upload.
*
* @default Incomplete uploads are never aborted
* @default - Incomplete uploads are never aborted
*/
readonly abortIncompleteMultipartUploadAfter?: Duration;

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

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

Expand All @@ -62,7 +62,7 @@ export interface LifecycleRule {
* and expiration time, the expiration time must be later than the
* transition time.
*
* @default No noncurrent version expiration
* @default - No noncurrent version expiration
*/
readonly noncurrentVersionExpiration?: Duration;

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

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

/**
* Object key prefix that identifies one or more objects to which this rule applies.
*
* @default Rule applies to all objects
* @default - Rule applies to all objects
*/
readonly prefix?: string;

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

Expand All @@ -118,6 +118,13 @@ export interface LifecycleRule {
* @default false
*/
readonly expiredObjectDeleteMarker?: boolean;

/**
* Specifies the minimum object size in bytes for this rule to apply to.
*
* @default - No rule
*/
readonly objectSizeGreaterThan?: number;
}

/**
Expand All @@ -134,14 +141,14 @@ export interface Transition {
*
* The date value must be in ISO 8601 format. The time is always midnight UTC.
*
* @default No transition date.
* @default - No transition date.
*/
readonly transitionDate?: Date;

/**
* Indicates the number of days after creation when objects are transitioned to the specified storage class.
*
* @default No transition count.
* @default - No transition count.
*/
readonly transitionAfter?: Duration;
}
Expand All @@ -158,14 +165,14 @@ export interface NoncurrentVersionTransition {
/**
* Indicates the number of days after creation when objects are transitioned to the specified storage class.
*
* @default No transition count.
* @default - No transition count.
*/
readonly transitionAfter: Duration;

/**
* Indicates the number of noncurrent version objects to be retained. Can be up to 100 noncurrent versions retained.
*
* @default No noncurrent version retained.
* @default - No noncurrent version retained.
*/
readonly noncurrentVersionsToRetain?: number;
}
Expand Down
11 changes: 8 additions & 3 deletions packages/@aws-cdk/aws-s3/test/integ.lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ const stack = new Stack(app, 'aws-cdk-s3');

// Test a lifecycle rule with an expiration DATE
new Bucket(stack, 'MyBucket', {
lifecycleRules: [{
expirationDate: new Date('2019-10-01'),
}],
lifecycleRules: [
{
expirationDate: new Date('2019-10-01'),
},
{
objectSizeGreaterThan: 500,
},
],
removalPolicy: RemovalPolicy.DESTROY,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
{
"ExpirationDate": "2019-10-01T00:00:00",
"Status": "Enabled"
},
{
"ObjectSizeGreaterThan": "500",
"Status": "Enabled"
}
]
}
Expand Down
22 changes: 22 additions & 0 deletions packages/@aws-cdk/aws-s3/test/rules.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,4 +291,26 @@ describe('rules', () => {
},
});
});

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

// WHEN
new Bucket(stack, 'Bucket', {
lifecycleRules: [{
objectSizeGreaterThan: 0,
}],
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::S3::Bucket', {
LifecycleConfiguration: {
Rules: [{
ObjectSizeGreaterThan: 0,
Status: 'Enabled',
}],
},
});
});
});

0 comments on commit 23690e4

Please sign in to comment.