Skip to content

Commit 65414c6

Browse files
authored
feat(efs): add support for transitioning files from infrequent access to primary storage (#16522)
This PR adds support for [TransitionToPrimaryStorageClass](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-efs-filesystem-lifecyclepolicy.html) for ``AWS::EFS::FileSystem`` ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent dc38bf0 commit 65414c6

File tree

3 files changed

+56
-3
lines changed

3 files changed

+56
-3
lines changed

packages/@aws-cdk/aws-efs/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const fileSystem = new efs.FileSystem(this, 'MyEfsFileSystem', {
3636
vpc: new ec2.Vpc(this, 'VPC'),
3737
lifecyclePolicy: efs.LifecyclePolicy.AFTER_14_DAYS, // files are not transitioned to infrequent access (IA) storage by default
3838
performanceMode: efs.PerformanceMode.GENERAL_PURPOSE, // default
39+
outInfrequentAccessPolicy: efs.OutOfInfrequentAccessPolicy.AFTER_1_ACCESS, // files are not transitioned back from (infrequent access) IA to primary storage by default
3940
});
4041
```
4142

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

+26-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@ export enum LifecyclePolicy {
4242
AFTER_90_DAYS = 'AFTER_90_DAYS'
4343
}
4444

45+
/**
46+
* EFS Out Of Infrequent Access Policy, if a file is accessed given times, it will move back to primary
47+
* storage class.
48+
*
49+
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-efs-filesystem-lifecyclepolicy.html#cfn-efs-filesystem-lifecyclepolicy-transitiontoprimarystorageclass
50+
*/
51+
export enum OutOfInfrequentAccessPolicy {
52+
/**
53+
* After 1 access
54+
*/
55+
AFTER_1_ACCESS = 'AFTER_1_ACCESS'
56+
}
57+
4558
/**
4659
* EFS Performance mode.
4760
*
@@ -165,6 +178,13 @@ export interface FileSystemProps {
165178
*/
166179
readonly lifecyclePolicy?: LifecyclePolicy;
167180

181+
/**
182+
* A policy used by EFS lifecycle management to transition files from Infrequent Access (IA) storage class to
183+
* primary storage class.
184+
*
185+
* @default - None. EFS will not transition files from IA storage to primary storage.
186+
*/
187+
readonly outOfInfrequentAccessPolicy?: OutOfInfrequentAccessPolicy;
168188
/**
169189
* The performance mode that the file system will operate under.
170190
* An Amazon EFS file system's performance mode can't be changed after the file system has been created.
@@ -324,7 +344,12 @@ export class FileSystem extends FileSystemBase {
324344
const filesystem = new CfnFileSystem(this, 'Resource', {
325345
encrypted: encrypted,
326346
kmsKeyId: props.kmsKey?.keyArn,
327-
lifecyclePolicies: (props.lifecyclePolicy ? [{ transitionToIa: props.lifecyclePolicy }] : undefined),
347+
lifecyclePolicies: (
348+
(props.lifecyclePolicy || props.outOfInfrequentAccessPolicy) ?
349+
[{
350+
transitionToIa: props.lifecyclePolicy,
351+
transitionToPrimaryStorageClass: props.outOfInfrequentAccessPolicy,
352+
}] : undefined),
328353
performanceMode: props.performanceMode,
329354
throughputMode: props.throughputMode,
330355
provisionedThroughputInMibps: props.provisionedThroughputPerSecond?.toMebibytes(),

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

+29-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { Template, Match } from '@aws-cdk/assertions';
22
import * as ec2 from '@aws-cdk/aws-ec2';
33
import * as iam from '@aws-cdk/aws-iam';
44
import * as kms from '@aws-cdk/aws-kms';
5+
import { testFutureBehavior, testLegacyBehavior } from '@aws-cdk/cdk-build-tools/lib/feature-flag';
56
import { App, RemovalPolicy, Size, Stack, Tags } from '@aws-cdk/core';
67
import * as cxapi from '@aws-cdk/cx-api';
7-
import { testFutureBehavior, testLegacyBehavior } from '@aws-cdk/cdk-build-tools/lib/feature-flag';
8-
import { FileSystem, LifecyclePolicy, PerformanceMode, ThroughputMode } from '../lib';
8+
import { FileSystem, LifecyclePolicy, PerformanceMode, ThroughputMode, OutOfInfrequentAccessPolicy } from '../lib';
99

1010
let stack = new Stack();
1111
let vpc = new ec2.Vpc(stack, 'VPC');
@@ -128,6 +128,33 @@ test('file system is created correctly with a life cycle property', () => {
128128
});
129129
});
130130

131+
test('file system is created correctly with a life cycle property and out of infrequent access property', () => {
132+
// WHEN
133+
new FileSystem(stack, 'EfsFileSystem', {
134+
vpc,
135+
lifecyclePolicy: LifecyclePolicy.AFTER_7_DAYS,
136+
outOfInfrequentAccessPolicy: OutOfInfrequentAccessPolicy.AFTER_1_ACCESS,
137+
});
138+
// THEN
139+
Template.fromStack(stack).hasResourceProperties('AWS::EFS::FileSystem', {
140+
LifecyclePolicies: [{
141+
TransitionToIA: 'AFTER_7_DAYS',
142+
TransitionToPrimaryStorageClass: 'AFTER_1_ACCESS',
143+
}],
144+
});
145+
});
146+
147+
test('LifecyclePolicies should be disabled when lifecyclePolicy and outInfrequentAccessPolicy are not specified', () => {
148+
// WHEN
149+
new FileSystem(stack, 'EfsFileSystem', {
150+
vpc,
151+
});
152+
// THEN
153+
Template.fromStack(stack).hasResourceProperties('AWS::EFS::FileSystem', {
154+
LifecyclePolicies: Match.absent(),
155+
});
156+
});
157+
131158
test('file system is created correctly with performance mode', () => {
132159
// WHEN
133160
new FileSystem(stack, 'EfsFileSystem', {

0 commit comments

Comments
 (0)