Skip to content

Commit 29dcb0a

Browse files
author
Niranjan Jayakar
committed
chore(efs): align construct library to latest standards
- Drop the `Efs` prefix to the exported types. - Change the type of provisioned throughput property to use `Size`. BREAKING CHANGE: Exported types no longer have the `Efs` prefix. * **efs:** `provisionedThroughputInMibps` property is renamed to `provisionedThroughputInSeconds` and has the type `Size`.
1 parent 94a7f98 commit 29dcb0a

File tree

3 files changed

+67
-107
lines changed

3 files changed

+67
-107
lines changed

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

+31-50
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import * as ec2 from '@aws-cdk/aws-ec2';
22
import * as kms from '@aws-cdk/aws-kms';
3-
import {Construct, Resource, Tag} from '@aws-cdk/core';
4-
import {CfnFileSystem, CfnMountTarget} from './efs.generated';
3+
import { Construct, IResource, Resource, Size, Tag } from '@aws-cdk/core';
4+
import { CfnFileSystem, CfnMountTarget } from './efs.generated';
55

6-
// tslint:disable: max-line-length
6+
// tslint:disable:max-line-length
77
/**
88
* EFS Lifecycle Policy, if a file is not accessed for given days, it will move to EFS Infrequent Access.
99
*
1010
* @see http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-efs-filesystem.html#cfn-elasticfilesystem-filesystem-lifecyclepolicies
1111
*/
12-
export enum EfsLifecyclePolicyProperty {
12+
// tslint:enable
13+
export enum LifecyclePolicyProperty {
1314
/**
1415
* After 7 days of not being accessed.
1516
*/
@@ -41,7 +42,7 @@ export enum EfsLifecyclePolicyProperty {
4142
*
4243
* @see http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-efs-filesystem.html#cfn-efs-filesystem-performancemode
4344
*/
44-
export enum EfsPerformanceMode {
45+
export enum PerformanceMode {
4546
/**
4647
* This is the general purpose performance mode for most file systems.
4748
*/
@@ -59,7 +60,7 @@ export enum EfsPerformanceMode {
5960
*
6061
* @see http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-efs-filesystem.html#cfn-elasticfilesystem-filesystem-throughputmode
6162
*/
62-
export enum EfsThroughputMode {
63+
export enum ThroughputMode {
6364
/**
6465
* This mode on Amazon EFS scales as the size of the file system in the standard storage class grows.
6566
*/
@@ -74,7 +75,7 @@ export enum EfsThroughputMode {
7475
/**
7576
* Interface to implement AWS File Systems.
7677
*/
77-
export interface IEfsFileSystem extends ec2.IConnectable {
78+
export interface IFileSystem extends ec2.IConnectable, IResource {
7879
/**
7980
* The ID of the file system, assigned by Amazon EFS.
8081
*
@@ -86,7 +87,7 @@ export interface IEfsFileSystem extends ec2.IConnectable {
8687
/**
8788
* Properties of EFS FileSystem.
8889
*/
89-
export interface EfsFileSystemProps {
90+
export interface FileSystemProps {
9091

9192
/**
9293
* VPC to launch the file system in.
@@ -133,51 +134,36 @@ export interface EfsFileSystemProps {
133134
*
134135
* @default - none
135136
*/
136-
readonly lifecyclePolicy?: EfsLifecyclePolicyProperty;
137+
readonly lifecyclePolicy?: LifecyclePolicyProperty;
137138

138139
/**
139140
* Enum to mention the performance mode of the file system.
140141
*
141142
* @default - GENERAL_PURPOSE
142143
*/
143-
readonly performanceMode?: EfsPerformanceMode;
144+
readonly performanceMode?: PerformanceMode;
144145

145146
/**
146147
* Enum to mention the throughput mode of the file system.
147148
*
148149
* @default - BURSTING
149150
*/
150-
readonly throughputMode?: EfsThroughputMode;
151+
readonly throughputMode?: ThroughputMode;
151152

152153
/**
153-
* Provisioned throughput for the file system. This is a required property if the throughput mode is set to PROVISIONED.
154-
* Valid values are 1-1024.
154+
* Provisioned throughput for the file system.
155+
* This is a required property if the throughput mode is set to PROVISIONED.
156+
* Valid values are 1MiB/s -> 1GiB/s
155157
*
156158
* @default - None, errors out
157159
*/
158-
readonly provisionedThroughputInMibps?: number;
159-
}
160-
161-
/**
162-
* A new or imported EFS File System.
163-
*/
164-
abstract class EfsFileSystemBase extends Resource implements IEfsFileSystem {
165-
166-
/**
167-
* The security groups/rules used to allow network connections to the file system.
168-
*/
169-
public abstract readonly connections: ec2.Connections;
170-
171-
/**
172-
* @attribute
173-
*/
174-
public abstract readonly fileSystemId: string;
160+
readonly provisionedThroughputPerSecond?: Size;
175161
}
176162

177163
/**
178164
* Properties that describe an existing EFS file system.
179165
*/
180-
export interface EfsFileSystemAttributes {
166+
export interface FileSystemAttributes {
181167
/**
182168
* The security group of the file system
183169
*/
@@ -199,17 +185,17 @@ export interface EfsFileSystemAttributes {
199185
*
200186
* @resource AWS::EFS::FileSystem
201187
*/
202-
export class EfsFileSystem extends EfsFileSystemBase {
188+
export class FileSystem extends Resource implements IFileSystem {
203189

204190
/**
205191
* Import an existing File System from the given properties.
206192
*/
207-
public static fromEfsFileSystemAttributes(scope: Construct, id: string, attrs: EfsFileSystemAttributes): IEfsFileSystem {
208-
class Import extends EfsFileSystemBase implements IEfsFileSystem {
193+
public static fromFileSystemAttributes(scope: Construct, id: string, attrs: FileSystemAttributes): IFileSystem {
194+
class Import extends Resource implements IFileSystem {
209195
public readonly fileSystemId = attrs.fileSystemID;
210196
public readonly connections = new ec2.Connections({
211197
securityGroups: [attrs.securityGroup],
212-
defaultPort: ec2.Port.tcp(EfsFileSystem.DEFAULT_PORT),
198+
defaultPort: ec2.Port.tcp(FileSystem.DEFAULT_PORT),
213199
});
214200
}
215201

@@ -231,37 +217,32 @@ export class EfsFileSystem extends EfsFileSystemBase {
231217
*/
232218
public readonly fileSystemId: string;
233219

234-
private readonly efsFileSystem: CfnFileSystem;
235-
236220
/**
237221
* Constructor for creating a new EFS FileSystem.
238222
*/
239-
constructor(scope: Construct, id: string, props: EfsFileSystemProps) {
223+
constructor(scope: Construct, id: string, props: FileSystemProps) {
240224
super(scope, id);
241225

242-
if (props.throughputMode === EfsThroughputMode.PROVISIONED) {
243-
if (props.provisionedThroughputInMibps === undefined) {
226+
if (props.throughputMode === ThroughputMode.PROVISIONED) {
227+
if (props.provisionedThroughputPerSecond === undefined) {
244228
throw new Error('Property provisionedThroughputInMibps is required when throughputMode is PROVISIONED');
245-
} else if (!Number.isInteger(props.provisionedThroughputInMibps)) {
246-
throw new Error('Invalid input for provisionedThroughputInMibps');
247-
} else if (props.provisionedThroughputInMibps < 1 || props.provisionedThroughputInMibps > 1024) {
248-
this.node.addWarning('Valid values for throughput are 1-1024 MiB/s. You can get this limit increased by contacting AWS Support.');
229+
} else if (props.provisionedThroughputPerSecond.toMebibytes() > 1024) {
230+
throw new Error('Valid values for throughput are 1MiB/s - 1GiB/s. You can get this limit increased by contacting AWS Support.');
249231
}
250232
}
251233

252-
this.efsFileSystem = new CfnFileSystem(this, 'Resource', {
234+
const filesystem = new CfnFileSystem(this, 'Resource', {
253235
encrypted: props.encrypted,
254236
kmsKeyId: (props.kmsKey ? props.kmsKey.keyId : undefined),
255237
lifecyclePolicies: (props.lifecyclePolicy ? Array.of({
256-
transitionToIa: EfsLifecyclePolicyProperty[props.lifecyclePolicy],
238+
transitionToIa: LifecyclePolicyProperty[props.lifecyclePolicy],
257239
} as CfnFileSystem.LifecyclePolicyProperty) : undefined),
258240
performanceMode: props.performanceMode,
259241
throughputMode: props.throughputMode,
260-
provisionedThroughputInMibps: props.provisionedThroughputInMibps,
242+
provisionedThroughputInMibps: props.provisionedThroughputPerSecond ? props.provisionedThroughputPerSecond.toMebibytes() : undefined,
261243
});
262244

263-
this.fileSystemId = this.efsFileSystem.ref;
264-
this.node.defaultChild = this.efsFileSystem;
245+
this.fileSystemId = filesystem.ref;
265246
Tag.add(this, 'Name', props.fileSystemName || this.node.path);
266247

267248
const securityGroup = (props.securityGroup || new ec2.SecurityGroup(this, 'EfsSecurityGroup', {
@@ -270,7 +251,7 @@ export class EfsFileSystem extends EfsFileSystemBase {
270251

271252
this.connections = new ec2.Connections({
272253
securityGroups: [securityGroup],
273-
defaultPort: ec2.Port.tcp(EfsFileSystem.DEFAULT_PORT),
254+
defaultPort: ec2.Port.tcp(FileSystem.DEFAULT_PORT),
274255
});
275256

276257
const subnets = props.vpc.selectSubnets(props.vpcSubnets);

packages/@aws-cdk/aws-efs/package.json

-8
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,6 @@
104104
"engines": {
105105
"node": ">= 10.12.0"
106106
},
107-
"awslint": {
108-
"exclude": [
109-
"props-physical-name:@aws-cdk/aws-efs.EfsFileSystemProps",
110-
"resource-interface:@aws-cdk/aws-efs.EfsFileSystem",
111-
"construct-interface-extends-iconstruct:@aws-cdk/aws-efs.IEfsFileSystem",
112-
"resource-interface-extends-resource:@aws-cdk/aws-efs.IEfsFileSystem"
113-
]
114-
},
115107
"stability": "experimental",
116108
"maturity": "experimental",
117109
"awscdkio": {

0 commit comments

Comments
 (0)