diff --git a/packages/@aws-cdk/aws-s3/README.md b/packages/@aws-cdk/aws-s3/README.md index c2f87f1186a3c..988b360c01d3c 100644 --- a/packages/@aws-cdk/aws-s3/README.md +++ b/packages/@aws-cdk/aws-s3/README.md @@ -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, diff --git a/packages/@aws-cdk/aws-s3/lib/bucket.ts b/packages/@aws-cdk/aws-s3/lib/bucket.ts index c1d73f54a0313..d51d79165f61c 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), + objectSizeGreaterThan: rule.objectSizeGreaterThan, }; return x; diff --git a/packages/@aws-cdk/aws-s3/lib/rule.ts b/packages/@aws-cdk/aws-s3/lib/rule.ts index 9baf32efb9779..b79af075ed848 100644 --- a/packages/@aws-cdk/aws-s3/lib/rule.ts +++ b/packages/@aws-cdk/aws-s3/lib/rule.ts @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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}; @@ -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; } /** @@ -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; } @@ -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; } diff --git a/packages/@aws-cdk/aws-s3/test/integ.lifecycle.ts b/packages/@aws-cdk/aws-s3/test/integ.lifecycle.ts index 05fe7bbf32ee2..0fe92eda9a7eb 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'), + }, + { + objectSizeGreaterThan: 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..df2d4d718d3cf 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" + }, + { + "ObjectSizeGreaterThan": "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..5be1225ebc4d1 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 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', + }], + }, + }); + }); });