@@ -10,6 +10,8 @@ import {
10
10
aws_cloudfront as cloudfront ,
11
11
aws_lambda as lambda ,
12
12
aws_cloudfront_origins as origins ,
13
+ aws_efs as efs ,
14
+ aws_ec2 as ec2 ,
13
15
aws_route53 as route53 ,
14
16
aws_s3 as s3 ,
15
17
aws_s3_deployment as s3deploy ,
@@ -38,7 +40,10 @@ export class StacksCloud extends Stack {
38
40
publicBucket : s3 . Bucket
39
41
privateBucket : s3 . Bucket
40
42
logBucket : s3 . Bucket | undefined
43
+ fileSystem ?: efs . FileSystem | undefined
44
+ accessPoint ?: efs . AccessPoint | undefined
41
45
}
46
+ vpc ! : ec2 . Vpc
42
47
43
48
cdn : cloudfront . Distribution
44
49
certificate ! : acm . Certificate
@@ -65,6 +70,7 @@ export class StacksCloud extends Stack {
65
70
this . manageCertificate ( )
66
71
this . manageStorage ( )
67
72
this . manageFirewall ( )
73
+ this . manageFileSystem ( )
68
74
69
75
const { cdn, originAccessIdentity, cdnCachePolicy } = this . manageCdn ( )
70
76
this . cdn = cdn
@@ -125,9 +131,10 @@ export class StacksCloud extends Stack {
125
131
} )
126
132
127
133
const serverFunction = new lambda . Function ( this , 'StacksServer' , {
134
+ functionName : `${ config . app . name } -${ config . app . env } -server` ,
128
135
description : 'The Stacks Server' ,
129
136
memorySize : 512 ,
130
- // filesystem: lambda.FileSystem.fromEfsAccessPoint(efsAccessPoint , '/mnt/efs'),
137
+ filesystem : lambda . FileSystem . fromEfsAccessPoint ( this . storage . accessPoint ! , '/mnt/efs' ) ,
131
138
timeout : Duration . seconds ( 30 ) ,
132
139
tracing : lambda . Tracing . ACTIVE ,
133
140
code : lambda . Code . fromAsset ( p . projectStoragePath ( 'framework/cloud/lambda.zip' ) ) ,
@@ -294,6 +301,30 @@ export class StacksCloud extends Stack {
294
301
} )
295
302
}
296
303
304
+
305
+ manageFileSystem ( ) {
306
+ this . vpc = new ec2 . Vpc ( this , 'StacksVpc' , {
307
+ maxAzs : 2 ,
308
+ natGateways : 1 ,
309
+ } )
310
+
311
+ this . storage . fileSystem = new efs . FileSystem ( this , 'StacksFileSystem' , {
312
+ vpc : this . vpc ,
313
+ fileSystemName : `${ config . app . name } -${ config . app . env } -efs` ,
314
+ removalPolicy : RemovalPolicy . DESTROY ,
315
+ lifecyclePolicy : efs . LifecyclePolicy . AFTER_7_DAYS ,
316
+ } )
317
+
318
+ this . storage . accessPoint = new efs . AccessPoint ( this , 'StacksAccessPoint' , {
319
+ fileSystem : this . storage . fileSystem ,
320
+ path : '/public' ,
321
+ posixUser : {
322
+ uid : '1000' ,
323
+ gid : '1000' ,
324
+ } ,
325
+ } )
326
+ }
327
+
297
328
manageCdn ( ) {
298
329
const originAccessIdentity = new cloudfront . OriginAccessIdentity ( this , 'OAI' )
299
330
0 commit comments