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

feat(s3): adds objectSizeGreaterThan property for s3 lifecycle rule #20425

Merged
merged 4 commits into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
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',
}],
},
});
});
});