From 99bdf08811c54dd4fea0b5b73530cf4ef7bf5799 Mon Sep 17 00:00:00 2001 From: Joshua Weber Date: Fri, 20 May 2022 00:29:19 +0200 Subject: [PATCH 1/4] :memo: feat(s3): adds objectSizeGreaterThan property for s3 lifecycle rule --- packages/@aws-cdk/aws-s3/lib/bucket.ts | 1 + packages/@aws-cdk/aws-s3/lib/rule.ts | 7 ++++++ .../@aws-cdk/aws-s3/test/integ.lifecycle.ts | 11 +++++++--- .../aws-cdk-s3.template.json | 4 ++++ packages/@aws-cdk/aws-s3/test/rules.test.ts | 22 +++++++++++++++++++ 5 files changed, 42 insertions(+), 3 deletions(-) diff --git a/packages/@aws-cdk/aws-s3/lib/bucket.ts b/packages/@aws-cdk/aws-s3/lib/bucket.ts index c1d73f54a0313..fb654e45d5fe1 100644 --- a/packages/@aws-cdk/aws-s3/lib/bucket.ts +++ b/packages/@aws-cdk/aws-s3/lib/bucket.ts @@ -1923,6 +1923,7 @@ export class Bucket extends BucketBase { })), expiredObjectDeleteMarker: rule.expiredObjectDeleteMarker, tagFilters: self.parseTagFilters(rule.tagFilters), + objectSizeLessThan: rule.objectSizeLessThan, }; return x; diff --git a/packages/@aws-cdk/aws-s3/lib/rule.ts b/packages/@aws-cdk/aws-s3/lib/rule.ts index 9baf32efb9779..4828026defdeb 100644 --- a/packages/@aws-cdk/aws-s3/lib/rule.ts +++ b/packages/@aws-cdk/aws-s3/lib/rule.ts @@ -118,6 +118,13 @@ export interface LifecycleRule { * @default false */ readonly expiredObjectDeleteMarker?: boolean; + + /** + * Specifies the maximum object size in bytes for this rule to apply to. + * + * @default No rule + */ + readonly objectSizeLessThan?: number; } /** diff --git a/packages/@aws-cdk/aws-s3/test/integ.lifecycle.ts b/packages/@aws-cdk/aws-s3/test/integ.lifecycle.ts index 05fe7bbf32ee2..4ea3412fe6de6 100644 --- a/packages/@aws-cdk/aws-s3/test/integ.lifecycle.ts +++ b/packages/@aws-cdk/aws-s3/test/integ.lifecycle.ts @@ -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'), + }, + { + objectSizeLessThan: 500, + }, + ], removalPolicy: RemovalPolicy.DESTROY, }); diff --git a/packages/@aws-cdk/aws-s3/test/lifecycle.integ.snapshot/aws-cdk-s3.template.json b/packages/@aws-cdk/aws-s3/test/lifecycle.integ.snapshot/aws-cdk-s3.template.json index 239ff4567e498..4ae3eec3ed84f 100644 --- a/packages/@aws-cdk/aws-s3/test/lifecycle.integ.snapshot/aws-cdk-s3.template.json +++ b/packages/@aws-cdk/aws-s3/test/lifecycle.integ.snapshot/aws-cdk-s3.template.json @@ -8,6 +8,10 @@ { "ExpirationDate": "2019-10-01T00:00:00", "Status": "Enabled" + }, + { + "ObjectSizeLessThan": "500", + "Status": "Enabled" } ] } diff --git a/packages/@aws-cdk/aws-s3/test/rules.test.ts b/packages/@aws-cdk/aws-s3/test/rules.test.ts index 8432e35e67bc5..75b599c4dee4c 100644 --- a/packages/@aws-cdk/aws-s3/test/rules.test.ts +++ b/packages/@aws-cdk/aws-s3/test/rules.test.ts @@ -291,4 +291,26 @@ describe('rules', () => { }, }); }); + + test('Bucket with objectSizeLessThan', () => { + // GIVEN + const stack = new Stack(); + + // WHEN + new Bucket(stack, 'Bucket', { + lifecycleRules: [{ + objectSizeLessThan: 0, + }], + }); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::S3::Bucket', { + LifecycleConfiguration: { + Rules: [{ + ObjectSizeLessThan: 0, + Status: 'Enabled', + }], + }, + }); + }); }); From e946b58be6964b9eb04261e5aa36111fde90d503 Mon Sep 17 00:00:00 2001 From: Joshua Weber Date: Tue, 24 May 2022 22:34:49 +0200 Subject: [PATCH 2/4] :memo: Adds objectSizeLessThan to README --- packages/@aws-cdk/aws-s3/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/@aws-cdk/aws-s3/README.md b/packages/@aws-cdk/aws-s3/README.md index ddf1f9a729d48..8c0d8ff0d1076 100644 --- a/packages/@aws-cdk/aws-s3/README.md +++ b/packages/@aws-cdk/aws-s3/README.md @@ -577,6 +577,7 @@ const bucket = new s3.Bucket(this, 'MyBucket', { noncurrentVersionsToRetain: 123, }], prefix: 'prefix', + objectSizeLessThan: 10000, transitions: [{ storageClass: s3.StorageClass.GLACIER, From bf0cc7f6a80c2801d92a0d9c834f4ef86d4db688 Mon Sep 17 00:00:00 2001 From: Calvin Combs Date: Tue, 24 May 2022 16:44:53 -0700 Subject: [PATCH 3/4] formatting --- packages/@aws-cdk/aws-s3/lib/rule.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-s3/lib/rule.ts b/packages/@aws-cdk/aws-s3/lib/rule.ts index 4828026defdeb..822def6df3708 100644 --- a/packages/@aws-cdk/aws-s3/lib/rule.ts +++ b/packages/@aws-cdk/aws-s3/lib/rule.ts @@ -122,7 +122,7 @@ export interface LifecycleRule { /** * Specifies the maximum object size in bytes for this rule to apply to. * - * @default No rule + * @default - No rule */ readonly objectSizeLessThan?: number; } From 3b54c4ce917c71b431f85252e52f8f6ff3bee2cd Mon Sep 17 00:00:00 2001 From: Joshua Weber Date: Wed, 25 May 2022 22:01:03 +0200 Subject: [PATCH 4/4] :rotating_light: Fixes linting error --- packages/@aws-cdk/aws-s3/lib/rule.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-s3/lib/rule.ts b/packages/@aws-cdk/aws-s3/lib/rule.ts index 6a7f83f0ed1cd..943130c1a20f9 100644 --- a/packages/@aws-cdk/aws-s3/lib/rule.ts +++ b/packages/@aws-cdk/aws-s3/lib/rule.ts @@ -125,7 +125,7 @@ export interface LifecycleRule { * @default - No rule */ readonly objectSizeLessThan?: number; - + /** Specifies the minimum object size in bytes for this rule to apply to. * * @default - No rule