-
Notifications
You must be signed in to change notification settings - Fork 4k
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
chore(s3): add validation on required properties for lifecycle rules #31806
Conversation
expect(() => { | ||
Template.fromStack(stack); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An error occurs in synthesize phase because the rendering is done as Lazy:
https://github.com/aws/aws-cdk/blob/v2.162.1/packages/aws-cdk-lib/aws-s3/lib/bucket.ts#L1941
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
@@ -2254,6 +2254,19 @@ export class Bucket extends BucketBase { | |||
throw new Error('ExpiredObjectDeleteMarker cannot be specified with expiration, ExpirationDate, or TagFilters.'); | |||
} | |||
|
|||
if ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @go-to-k and the unit testing - I'm now wondering how we missed this validation in the first place.
This is certainly a big if
statement here, but I suppose it has to be for this validation. Trying to think of other ways to format this ...
const ruleProperties = [
rule.abortIncompleteMultipartUploadAfter,
rule.expiration,
rule.expirationDate,
rule.expiredObjectDeleteMarker,
rule.noncurrentVersionExpiration,
rule.noncurrentVersionsToRetain,
rule.noncurrentVersionTransitions,
rule.transitions,
];
if (ruleProperties.every(prop => prop === 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`');
}
Approving this PR 👍
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
Comments on closed issues and PRs are hard for our team to see. |
Issue # (if applicable)
Closes #.
Reason for this change
If there is a lifecycle rule that does not contain one of the specified properties, an error is raised.
A CFn message:
The properties in CFn properties:
The properties in L2 props:
Description of changes
Check whether a rule has required properties in lifecycleRules for L2 BucketProps.
Description of how you validated changes
Unit tests.
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license