Skip to content

Commit d435ab6

Browse files
authored
fix(efs): fix bug when setting both lifecyclePolicy and outOfInfrequentAccessPolicy (#19082)
Closes #19058 Most likely this was an oversight in CloudFormation docs. Submitted a PR for CF docs here: awsdocs/aws-cloudformation-user-guide#1165 Here are the API docs showing the proper parameters for LifecyclePolicies: https://docs.aws.amazon.com/efs/latest/ug/API_PutLifecycleConfiguration.html <img width="418" alt="image" src="https://user-images.githubusercontent.com/31543/155045177-308d0608-bc11-4150-8d5f-b7da7f8f5b01.png"> <img width="1226" alt="Screen Shot 2022-02-21 at 5 14 50 PM" src="https://user-images.githubusercontent.com/31543/155045111-31e9d9b5-99b1-404f-bee7-61dd3e2751f2.png"> <img width="679" alt="Screen Shot 2022-02-21 at 5 14 57 PM" src="https://user-images.githubusercontent.com/31543/155045114-a56c68f7-60f4-4a6c-946a-1231cdf84448.png"> ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 8b6c907 commit d435ab6

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

packages/@aws-cdk/aws-efs/lib/efs-file-system.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -341,15 +341,21 @@ export class FileSystem extends FileSystemBase {
341341
const encrypted = props.encrypted ?? (FeatureFlags.of(this).isEnabled(
342342
cxapi.EFS_DEFAULT_ENCRYPTION_AT_REST) ? true : undefined);
343343

344+
// LifecyclePolicies is an array of lists containing a single policy
345+
let lifecyclePolicies = [];
346+
347+
if (props.lifecyclePolicy) {
348+
lifecyclePolicies.push({ transitionToIa: props.lifecyclePolicy });
349+
}
350+
351+
if (props.outOfInfrequentAccessPolicy) {
352+
lifecyclePolicies.push({ transitionToPrimaryStorageClass: props.outOfInfrequentAccessPolicy });
353+
}
354+
344355
const filesystem = new CfnFileSystem(this, 'Resource', {
345356
encrypted: encrypted,
346357
kmsKeyId: props.kmsKey?.keyArn,
347-
lifecyclePolicies: (
348-
(props.lifecyclePolicy || props.outOfInfrequentAccessPolicy) ?
349-
[{
350-
transitionToIa: props.lifecyclePolicy,
351-
transitionToPrimaryStorageClass: props.outOfInfrequentAccessPolicy,
352-
}] : undefined),
358+
lifecyclePolicies: lifecyclePolicies.length > 0 ? lifecyclePolicies : undefined,
353359
performanceMode: props.performanceMode,
354360
throughputMode: props.throughputMode,
355361
provisionedThroughputInMibps: props.provisionedThroughputPerSecond?.toMebibytes(),

packages/@aws-cdk/aws-efs/test/efs-file-system.test.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,14 @@ test('file system is created correctly with a life cycle property and out of inf
137137
});
138138
// THEN
139139
Template.fromStack(stack).hasResourceProperties('AWS::EFS::FileSystem', {
140-
LifecyclePolicies: [{
141-
TransitionToIA: 'AFTER_7_DAYS',
142-
TransitionToPrimaryStorageClass: 'AFTER_1_ACCESS',
143-
}],
140+
LifecyclePolicies: [
141+
{
142+
TransitionToIA: 'AFTER_7_DAYS',
143+
},
144+
{
145+
TransitionToPrimaryStorageClass: 'AFTER_1_ACCESS',
146+
},
147+
],
144148
});
145149
});
146150

0 commit comments

Comments
 (0)