Skip to content

Commit

Permalink
feat(bucketLifecycle): allow for prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
richardkeit committed Jul 20, 2023
1 parent 0e75eeb commit 893278d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ export abstract class AcceleratorStack extends cdk.Stack {
expiration: lifecycleRule.expiration,
expiredObjectDeleteMarker: lifecycleRule.expiredObjectDeleteMarker,
id: lifecycleRule.id,
prefix: lifecycleRule.prefix,
noncurrentVersionExpiration: lifecycleRule.noncurrentVersionExpiration,
noncurrentVersionTransitions,
transitions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,7 @@ export class LoggingStack extends AcceleratorStack {
kmsKey: this.cloudwatchKey,
logRetentionInDays: this.props.globalConfig.cloudwatchLogRetentionInDays,
};

this.centralLogsBucket = new CentralLogsBucket(this, 'CentralLogsBucket', {
s3BucketName: this.centralLogsBucketName,
serverAccessLogsBucket: serverAccessLogsBucket,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ export const lifecycleRuleConfig = t.interface({
noncurrentVersionExpiration: optional(t.number),
noncurrentVersionTransitions: optional(t.array(transition)),
transitions: optional(t.array(transition)),
prefix: optional(t.string),
});

export const resourcePolicyStatement = t.interface({
Expand All @@ -355,6 +356,7 @@ export class LifeCycleRule implements t.TypeOf<typeof lifecycleRuleConfig> {
readonly noncurrentVersionExpiration: number = 366;
readonly noncurrentVersionTransitions: Transition[] = [];
readonly transitions: Transition[] = [];
readonly prefix: string = '';
}

export const shareTargets = t.interface({
Expand Down
10 changes: 6 additions & 4 deletions source/packages/@aws-accelerator/constructs/lib/aws-s3/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export interface S3LifeCycleRule {
noncurrentVersionExpiration: number;
transitions: Transition[];
noncurrentVersionTransitions: Transition[];
prefix: string;
}

/**
Expand Down Expand Up @@ -349,19 +350,20 @@ export class Bucket extends Construct {
};
noncurrentVersionTransitions.push(noncurrentVersionTransitionsConfig);
}

this.lifecycleRules.push({
const lifecycle = {
abortIncompleteMultipartUploadAfter: cdk.Duration.days(
lifecycleRuleConfig.abortIncompleteMultipartUploadAfter,
),
enabled: lifecycleRuleConfig.enabled,
expiration: cdk.Duration.days(lifecycleRuleConfig.expiration),
prefix: lifecycleRuleConfig.prefix,
transitions,
noncurrentVersionTransitions,
noncurrentVersionExpiration: cdk.Duration.days(lifecycleRuleConfig.noncurrentVersionExpiration),
expiredObjectDeleteMarker: lifecycleRuleConfig.expiredObjectDeleteMarker,
id: `LifecycleRule${this.props.s3BucketName}`,
});
id: `LifecycleRule${lifecycleRuleConfig.prefix}${this.props.s3BucketName}`,
}
this.lifecycleRules.push(lifecycle);
}
} else {
this.lifecycleRules.push({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ describe('Bucket', () => {
s3LifeCycleRules: [
{
id: '1',
prefix: 'object-prefix',
abortIncompleteMultipartUploadAfter: 1,
enabled: true,
expiration: 24,
Expand Down

0 comments on commit 893278d

Please sign in to comment.