Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(efs): support for new elastic throughputmode #23200

Merged
merged 13 commits into from
Dec 6, 2022
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-efs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ const fileSystem = new efs.FileSystem(this, 'MyEfsFileSystem', {
});
```

⚠️ An Amazon EFS file system's performance mode can't be MAX_IO when its throughputMode is ELASTIC.

⚠️ An Amazon EFS file system's performance mode can't be changed after the file system has been created.
Updating this property will replace the file system.

Expand Down
18 changes: 16 additions & 2 deletions packages/@aws-cdk/aws-efs/lib/efs-file-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ import { CfnFileSystem, CfnMountTarget } from './efs.generated';
* @see http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-efs-filesystem.html#cfn-elasticfilesystem-filesystem-lifecyclepolicies
*/
export enum LifecyclePolicy {

/**
* After 1 day of not being accessed.
*/
AFTER_1_DAY = 'AFTER_1_DAY',

/**
* After 7 days of not being accessed.
*/
Expand Down Expand Up @@ -82,14 +88,19 @@ export enum PerformanceMode {
*/
export enum ThroughputMode {
/**
* This mode on Amazon EFS scales as the size of the file system in the standard storage class grows.
* This mode scales as the size of the file system in the standard storage class grows.
*/
BURSTING = 'bursting',

/**
* This mode can instantly provision the throughput of the file system (in MiB/s) independent of the amount of data stored.
*/
PROVISIONED = 'provisioned'
PROVISIONED = 'provisioned',

/**
* This mode scales the throughput automatically regardless of file system size.
*/
ELASTIC = 'elastic'
}

/**
Expand Down Expand Up @@ -333,6 +344,9 @@ export class FileSystem extends FileSystemBase {
throw new Error('Property provisionedThroughputPerSecond is required when throughputMode is PROVISIONED');
}

if (props.throughputMode === ThroughputMode.ELASTIC && props.performanceMode === PerformanceMode.MAX_IO) {
throw new Error('ThroughputMode ELASTIC is not supported for file systems with performanceMode MAX_IO');
}
// we explictly use 'undefined' to represent 'false' to maintain backwards compatibility since
// its considered an actual change in CloudFormations eyes, even though they have the same meaning.
const encrypted = props.encrypted ?? (FeatureFlags.of(this).isEnabled(
Expand Down
23 changes: 23 additions & 0 deletions packages/@aws-cdk/aws-efs/test/efs-file-system.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,29 @@ test('file system is created correctly with bursting throughput mode', () => {
});
});

test('file system is created correctly with elastic throughput mode', () => {
// WHEN
new FileSystem(stack, 'EfsFileSystem', {
vpc,
throughputMode: ThroughputMode.ELASTIC,
performanceMode: PerformanceMode.GENERAL_PURPOSE,
});
// THEN
Template.fromStack(stack).hasResourceProperties('AWS::EFS::FileSystem', {
ThroughputMode: 'elastic',
});
});

test('Exception when throughput mode is set to ELASTIC, performance mode cannot be MaxIO', () => {
expect(() => {
new FileSystem(stack, 'EfsFileSystem', {
vpc,
throughputMode: ThroughputMode.ELASTIC,
performanceMode: PerformanceMode.MAX_IO,
});
}).toThrowError(/ThroughputMode ELASTIC is not supported for file systems with performanceMode MAX_IO/);
});

test('Exception when throughput mode is set to PROVISIONED, but provisioned throughput is not set', () => {
expect(() => {
new FileSystem(stack, 'EfsFileSystem', {
Expand Down