Skip to content

Commit 1a82d85

Browse files
fix(s3): fail fast for s3 lifecycle configuration when ExpiredObjectDeleteMarker specified with ExpirationInDays, ExpirationDate, or TagFilters. (#25841)
Closes #25824. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent c135656 commit 1a82d85

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

packages/aws-cdk-lib/aws-s3/lib/bucket.ts

+5
Original file line numberDiff line numberDiff line change
@@ -2119,6 +2119,11 @@ export class Bucket extends BucketBase {
21192119

21202120
function parseLifecycleRule(rule: LifecycleRule): CfnBucket.RuleProperty {
21212121
const enabled = rule.enabled ?? true;
2122+
if ((rule.expiredObjectDeleteMarker)
2123+
&& (rule.expiration || rule.expirationDate || self.parseTagFilters(rule.tagFilters))) {
2124+
// ExpiredObjectDeleteMarker cannot be specified with ExpirationInDays, ExpirationDate, or TagFilters.
2125+
throw new Error('ExpiredObjectDeleteMarker cannot be specified with expiration, ExpirationDate, or TagFilters.');
2126+
}
21222127

21232128
const x: CfnBucket.RuleProperty = {
21242129
// eslint-disable-next-line max-len

packages/aws-cdk-lib/aws-s3/test/rules.test.ts

+45
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,51 @@ describe('rules', () => {
2525
});
2626
});
2727

28+
test('ExpiredObjectDeleteMarker cannot be specified with ExpirationInDays.', () => {
29+
const stack = new Stack();
30+
new Bucket(stack, 'Bucket', {
31+
lifecycleRules: [{
32+
expiration: Duration.days(30),
33+
expiredObjectDeleteMarker: true,
34+
}],
35+
});
36+
37+
expect(() => {
38+
Template.fromStack(stack).toJSON();
39+
}).toThrow('ExpiredObjectDeleteMarker cannot be specified with expiration, ExpirationDate, or TagFilters.');
40+
});
41+
42+
test('ExpiredObjectDeleteMarker cannot be specified with ExpirationDate.', () => {
43+
const stack = new Stack();
44+
new Bucket(stack, 'Bucket', {
45+
lifecycleRules: [{
46+
expirationDate: new Date('2018-01-01'),
47+
expiredObjectDeleteMarker: true,
48+
}],
49+
});
50+
51+
expect(() => {
52+
Template.fromStack(stack).toJSON();
53+
}).toThrow('ExpiredObjectDeleteMarker cannot be specified with expiration, ExpirationDate, or TagFilters.');
54+
});
55+
56+
test('ExpiredObjectDeleteMarker cannot be specified with TagFilters.', () => {
57+
const stack = new Stack();
58+
new Bucket(stack, 'Bucket', {
59+
lifecycleRules: [{
60+
tagFilters: [
61+
{ Key: 'tagname1', Value: 'tagvalue1' },
62+
{ Key: 'tagname2', Value: 'tagvalue2' },
63+
],
64+
expiredObjectDeleteMarker: true,
65+
}],
66+
});
67+
68+
expect(() => {
69+
Template.fromStack(stack).toJSON();
70+
}).toThrow('ExpiredObjectDeleteMarker cannot be specified with expiration, ExpirationDate, or TagFilters.');
71+
});
72+
2873
test('Can use addLifecycleRule() to add a lifecycle rule', () => {
2974
// GIVEN
3075
const stack = new Stack();

0 commit comments

Comments
 (0)