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 objectSizeLessThan property for s3 lifecycle rule #20429

Merged
merged 8 commits into from
May 31, 2022
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 @@ -578,6 +578,7 @@ const bucket = new s3.Bucket(this, 'MyBucket', {
}],
objectSizeGreaterThan: 500,
prefix: 'prefix',
objectSizeLessThan: 10000,
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),
objectSizeLessThan: rule.objectSizeLessThan,
objectSizeGreaterThan: rule.objectSizeGreaterThan,
};

Expand Down
8 changes: 7 additions & 1 deletion packages/@aws-cdk/aws-s3/lib/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,13 @@ export interface LifecycleRule {
readonly expiredObjectDeleteMarker?: boolean;

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

/** Specifies the minimum object size in bytes for this rule to apply to.
*
* @default - No rule
*/
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-s3/test/integ.lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ new Bucket(stack, 'MyBucket', {
expirationDate: new Date('2019-10-01'),
},
{
objectSizeLessThan: 500,
objectSizeGreaterThan: 500,
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"Status": "Enabled"
},
{
"ObjectSizeLessThan": "500",
"ObjectSizeGreaterThan": "500",
"Status": "Enabled"
}
Expand Down
4 changes: 3 additions & 1 deletion packages/@aws-cdk/aws-s3/test/rules.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,14 @@ describe('rules', () => {
});
});

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

// WHEN
new Bucket(stack, 'Bucket', {
lifecycleRules: [{
objectSizeLessThan: 0,
objectSizeGreaterThan: 0,
}],
});
Expand All @@ -307,6 +308,7 @@ describe('rules', () => {
Template.fromStack(stack).hasResourceProperties('AWS::S3::Bucket', {
LifecycleConfiguration: {
Rules: [{
ObjectSizeLessThan: 0,
ObjectSizeGreaterThan: 0,
Status: 'Enabled',
}],
Expand Down