Skip to content

Commit

Permalink
fix(efs): fix bug when setting both lifecyclePolicy and outOfInfreque…
Browse files Browse the repository at this point in the history
…ntAccessPolicy (#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*
  • Loading branch information
robertd committed Mar 1, 2022
1 parent 8b6c907 commit d435ab6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
18 changes: 12 additions & 6 deletions packages/@aws-cdk/aws-efs/lib/efs-file-system.ts
Expand Up @@ -341,15 +341,21 @@ export class FileSystem extends FileSystemBase {
const encrypted = props.encrypted ?? (FeatureFlags.of(this).isEnabled(
cxapi.EFS_DEFAULT_ENCRYPTION_AT_REST) ? true : undefined);

// LifecyclePolicies is an array of lists containing a single policy
let lifecyclePolicies = [];

if (props.lifecyclePolicy) {
lifecyclePolicies.push({ transitionToIa: props.lifecyclePolicy });
}

if (props.outOfInfrequentAccessPolicy) {
lifecyclePolicies.push({ transitionToPrimaryStorageClass: props.outOfInfrequentAccessPolicy });
}

const filesystem = new CfnFileSystem(this, 'Resource', {
encrypted: encrypted,
kmsKeyId: props.kmsKey?.keyArn,
lifecyclePolicies: (
(props.lifecyclePolicy || props.outOfInfrequentAccessPolicy) ?
[{
transitionToIa: props.lifecyclePolicy,
transitionToPrimaryStorageClass: props.outOfInfrequentAccessPolicy,
}] : undefined),
lifecyclePolicies: lifecyclePolicies.length > 0 ? lifecyclePolicies : undefined,
performanceMode: props.performanceMode,
throughputMode: props.throughputMode,
provisionedThroughputInMibps: props.provisionedThroughputPerSecond?.toMebibytes(),
Expand Down
12 changes: 8 additions & 4 deletions packages/@aws-cdk/aws-efs/test/efs-file-system.test.ts
Expand Up @@ -137,10 +137,14 @@ test('file system is created correctly with a life cycle property and out of inf
});
// THEN
Template.fromStack(stack).hasResourceProperties('AWS::EFS::FileSystem', {
LifecyclePolicies: [{
TransitionToIA: 'AFTER_7_DAYS',
TransitionToPrimaryStorageClass: 'AFTER_1_ACCESS',
}],
LifecyclePolicies: [
{
TransitionToIA: 'AFTER_7_DAYS',
},
{
TransitionToPrimaryStorageClass: 'AFTER_1_ACCESS',
},
],
});
});

Expand Down

0 comments on commit d435ab6

Please sign in to comment.