1
1
import * as ec2 from '@aws-cdk/aws-ec2' ;
2
2
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' ;
5
5
6
- // tslint:disable: max-line-length
6
+ // tslint:disable:max-line-length
7
7
/**
8
8
* EFS Lifecycle Policy, if a file is not accessed for given days, it will move to EFS Infrequent Access.
9
9
*
10
10
* @see http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-efs-filesystem.html#cfn-elasticfilesystem-filesystem-lifecyclepolicies
11
11
*/
12
- export enum EfsLifecyclePolicyProperty {
12
+ // tslint:enable
13
+ export enum LifecyclePolicyProperty {
13
14
/**
14
15
* After 7 days of not being accessed.
15
16
*/
@@ -41,7 +42,7 @@ export enum EfsLifecyclePolicyProperty {
41
42
*
42
43
* @see http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-efs-filesystem.html#cfn-efs-filesystem-performancemode
43
44
*/
44
- export enum EfsPerformanceMode {
45
+ export enum PerformanceMode {
45
46
/**
46
47
* This is the general purpose performance mode for most file systems.
47
48
*/
@@ -59,7 +60,7 @@ export enum EfsPerformanceMode {
59
60
*
60
61
* @see http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-efs-filesystem.html#cfn-elasticfilesystem-filesystem-throughputmode
61
62
*/
62
- export enum EfsThroughputMode {
63
+ export enum ThroughputMode {
63
64
/**
64
65
* This mode on Amazon EFS scales as the size of the file system in the standard storage class grows.
65
66
*/
@@ -74,7 +75,7 @@ export enum EfsThroughputMode {
74
75
/**
75
76
* Interface to implement AWS File Systems.
76
77
*/
77
- export interface IEfsFileSystem extends ec2 . IConnectable {
78
+ export interface IFileSystem extends ec2 . IConnectable , IResource {
78
79
/**
79
80
* The ID of the file system, assigned by Amazon EFS.
80
81
*
@@ -86,7 +87,7 @@ export interface IEfsFileSystem extends ec2.IConnectable {
86
87
/**
87
88
* Properties of EFS FileSystem.
88
89
*/
89
- export interface EfsFileSystemProps {
90
+ export interface FileSystemProps {
90
91
91
92
/**
92
93
* VPC to launch the file system in.
@@ -133,51 +134,36 @@ export interface EfsFileSystemProps {
133
134
*
134
135
* @default - none
135
136
*/
136
- readonly lifecyclePolicy ?: EfsLifecyclePolicyProperty ;
137
+ readonly lifecyclePolicy ?: LifecyclePolicyProperty ;
137
138
138
139
/**
139
140
* Enum to mention the performance mode of the file system.
140
141
*
141
142
* @default - GENERAL_PURPOSE
142
143
*/
143
- readonly performanceMode ?: EfsPerformanceMode ;
144
+ readonly performanceMode ?: PerformanceMode ;
144
145
145
146
/**
146
147
* Enum to mention the throughput mode of the file system.
147
148
*
148
149
* @default - BURSTING
149
150
*/
150
- readonly throughputMode ?: EfsThroughputMode ;
151
+ readonly throughputMode ?: ThroughputMode ;
151
152
152
153
/**
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
155
157
*
156
158
* @default - None, errors out
157
159
*/
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 ;
175
161
}
176
162
177
163
/**
178
164
* Properties that describe an existing EFS file system.
179
165
*/
180
- export interface EfsFileSystemAttributes {
166
+ export interface FileSystemAttributes {
181
167
/**
182
168
* The security group of the file system
183
169
*/
@@ -199,17 +185,17 @@ export interface EfsFileSystemAttributes {
199
185
*
200
186
* @resource AWS::EFS::FileSystem
201
187
*/
202
- export class EfsFileSystem extends EfsFileSystemBase {
188
+ export class FileSystem extends Resource implements IFileSystem {
203
189
204
190
/**
205
191
* Import an existing File System from the given properties.
206
192
*/
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 {
209
195
public readonly fileSystemId = attrs . fileSystemID ;
210
196
public readonly connections = new ec2 . Connections ( {
211
197
securityGroups : [ attrs . securityGroup ] ,
212
- defaultPort : ec2 . Port . tcp ( EfsFileSystem . DEFAULT_PORT ) ,
198
+ defaultPort : ec2 . Port . tcp ( FileSystem . DEFAULT_PORT ) ,
213
199
} ) ;
214
200
}
215
201
@@ -231,37 +217,32 @@ export class EfsFileSystem extends EfsFileSystemBase {
231
217
*/
232
218
public readonly fileSystemId : string ;
233
219
234
- private readonly efsFileSystem : CfnFileSystem ;
235
-
236
220
/**
237
221
* Constructor for creating a new EFS FileSystem.
238
222
*/
239
- constructor ( scope : Construct , id : string , props : EfsFileSystemProps ) {
223
+ constructor ( scope : Construct , id : string , props : FileSystemProps ) {
240
224
super ( scope , id ) ;
241
225
242
- if ( props . throughputMode === EfsThroughputMode . PROVISIONED ) {
243
- if ( props . provisionedThroughputInMibps === undefined ) {
226
+ if ( props . throughputMode === ThroughputMode . PROVISIONED ) {
227
+ if ( props . provisionedThroughputPerSecond === undefined ) {
244
228
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.' ) ;
249
231
}
250
232
}
251
233
252
- this . efsFileSystem = new CfnFileSystem ( this , 'Resource' , {
234
+ const filesystem = new CfnFileSystem ( this , 'Resource' , {
253
235
encrypted : props . encrypted ,
254
236
kmsKeyId : ( props . kmsKey ? props . kmsKey . keyId : undefined ) ,
255
237
lifecyclePolicies : ( props . lifecyclePolicy ? Array . of ( {
256
- transitionToIa : EfsLifecyclePolicyProperty [ props . lifecyclePolicy ] ,
238
+ transitionToIa : LifecyclePolicyProperty [ props . lifecyclePolicy ] ,
257
239
} as CfnFileSystem . LifecyclePolicyProperty ) : undefined ) ,
258
240
performanceMode : props . performanceMode ,
259
241
throughputMode : props . throughputMode ,
260
- provisionedThroughputInMibps : props . provisionedThroughputInMibps ,
242
+ provisionedThroughputInMibps : props . provisionedThroughputPerSecond ? props . provisionedThroughputPerSecond . toMebibytes ( ) : undefined ,
261
243
} ) ;
262
244
263
- this . fileSystemId = this . efsFileSystem . ref ;
264
- this . node . defaultChild = this . efsFileSystem ;
245
+ this . fileSystemId = filesystem . ref ;
265
246
Tag . add ( this , 'Name' , props . fileSystemName || this . node . path ) ;
266
247
267
248
const securityGroup = ( props . securityGroup || new ec2 . SecurityGroup ( this , 'EfsSecurityGroup' , {
@@ -270,7 +251,7 @@ export class EfsFileSystem extends EfsFileSystemBase {
270
251
271
252
this . connections = new ec2 . Connections ( {
272
253
securityGroups : [ securityGroup ] ,
273
- defaultPort : ec2 . Port . tcp ( EfsFileSystem . DEFAULT_PORT ) ,
254
+ defaultPort : ec2 . Port . tcp ( FileSystem . DEFAULT_PORT ) ,
274
255
} ) ;
275
256
276
257
const subnets = props . vpc . selectSubnets ( props . vpcSubnets ) ;
0 commit comments