Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(s3): add validation on required properties for lifecycle rules (#…
…31806) ### Issue # (if applicable) Closes #<issue number here>. ### Reason for this change If there is a lifecycle rule that does not contain one of the specified properties, an error is raised. ```ts const app = new App(); const stack = new Stack(app, 'aws-cdk-s3'); // An error occurs new Bucket(stack, 'MyBucket', { lifecycleRules: [ // is invalid { objectSizeLessThan: 300000, objectSizeGreaterThan: 200000, }, ], }); ``` ```ts const app = new App(); const stack = new Stack(app, 'aws-cdk-s3'); // An error occurs new Bucket(stack, 'MyBucket', { lifecycleRules: [ // is valid { abortIncompleteMultipartUploadAfter: Duration.days(365), }, // is invalid { objectSizeLessThan: 300000, objectSizeGreaterThan: 200000, }, ], }); ``` A CFn message: ``` Invalid request provided: At least one of [ExpirationDate,ExpirationInDays,AbortIncompleteMultipartUpload,Transition,Transitions,NoncurrentVersionExpirationInDays,NoncurrentVersionTransition,NoncurrentVersionTransitions,NoncurrentVersionExpiration,ExpiredObjectDeleteMarker] needs to be specified ``` The properties in CFn properties: - AbortIncompleteMultipartUpload - ExpirationDate - ExpirationInDays - ExpiredObjectDeleteMarker - NoncurrentVersionExpirationInDays - NoncurrentVersionTransition - NoncurrentVersionTransitions - NoncurrentVersionExpiration - Transition - Transitions The properties in L2 props: - abortIncompleteMultipartUploadAfter - expiration - expirationDate - expiredObjectDeleteMarker - noncurrentVersionExpiration - noncurrentVersionsToRetain - noncurrentVersionTransitions - transitions ### Description of changes Check whether a rule has required properties in lifecycleRules for L2 BucketProps. ```ts if ( rule.abortIncompleteMultipartUploadAfter === undefined && rule.expiration === undefined && rule.expirationDate === undefined && rule.expiredObjectDeleteMarker === undefined && rule.noncurrentVersionExpiration === undefined && rule.noncurrentVersionsToRetain === undefined && rule.noncurrentVersionTransitions === undefined && rule.transitions === undefined ) { throw new Error('All rules for `lifecycleRules` must have at least one of the following properties: `abortIncompleteMultipartUploadAfter`, `expiration`, `expirationDate`, `expiredObjectDeleteMarker`, `noncurrentVersionExpiration`, `noncurrentVersionsToRetain`, `noncurrentVersionTransitions`, or `transitions`'); } ``` ### Description of how you validated changes Unit tests. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information