From d7ae159a1ce3e332b39a6006a7f54683f2559938 Mon Sep 17 00:00:00 2001 From: smsruthi <115501487+smsruthi@users.noreply.github.com> Date: Tue, 6 Dec 2022 08:38:31 -0500 Subject: [PATCH] feat(efs): support for new `elastic` throughputmode (#23200) ---- ### All Submissions: * [ yes] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Construct Runtime Dependencies: * [ ] This PR adds new construct runtime dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-construct-runtime-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- packages/@aws-cdk/aws-efs/README.md | 2 ++ .../@aws-cdk/aws-efs/lib/efs-file-system.ts | 18 +++++++++++++-- .../aws-efs/test/efs-file-system.test.ts | 23 +++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/packages/@aws-cdk/aws-efs/README.md b/packages/@aws-cdk/aws-efs/README.md index 058198d0c897e..a0ea3b8432341 100644 --- a/packages/@aws-cdk/aws-efs/README.md +++ b/packages/@aws-cdk/aws-efs/README.md @@ -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. diff --git a/packages/@aws-cdk/aws-efs/lib/efs-file-system.ts b/packages/@aws-cdk/aws-efs/lib/efs-file-system.ts index b6f512ed071e6..57b7e295068f0 100644 --- a/packages/@aws-cdk/aws-efs/lib/efs-file-system.ts +++ b/packages/@aws-cdk/aws-efs/lib/efs-file-system.ts @@ -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. */ @@ -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' } /** @@ -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( diff --git a/packages/@aws-cdk/aws-efs/test/efs-file-system.test.ts b/packages/@aws-cdk/aws-efs/test/efs-file-system.test.ts index 39e172a479867..96715f688c968 100644 --- a/packages/@aws-cdk/aws-efs/test/efs-file-system.test.ts +++ b/packages/@aws-cdk/aws-efs/test/efs-file-system.test.ts @@ -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', {