1
1
/* eslint-disable no-new */
2
2
import type { Construct } from 'constructs'
3
- import type {
4
- CfnResource ,
5
- StackProps ,
6
- } from 'aws-cdk-lib'
3
+ import type { CfnResource , StackProps } from 'aws-cdk-lib'
7
4
import {
8
5
Duration ,
9
6
Fn ,
@@ -38,7 +35,7 @@ import type { EnvKey } from '~/storage/framework/stacks/env'
38
35
39
36
const appEnv = config . app . env === 'local' ? 'dev' : config . app . env
40
37
const timestamp = new Date ( ) . getTime ( )
41
- const s3Sdk = new S3 ( )
38
+ // const s3Sdk = new S3()
42
39
43
40
function isProductionEnv ( env : string ) {
44
41
return env === 'production' || env === 'prod'
@@ -80,7 +77,7 @@ export class StacksCloud extends Stack {
80
77
super ( scope , id , props )
81
78
}
82
79
83
- async init ( ) {
80
+ init ( ) {
84
81
// this is a noop function that is used to ensure the constructor is called
85
82
// @ts -expect-error – we know this was properly set when needed
86
83
this . storage = { }
@@ -105,9 +102,9 @@ export class StacksCloud extends Stack {
105
102
106
103
this . manageUsers ( )
107
104
this . manageZone ( )
108
- await this . manageEmailServer ( )
105
+ this . manageEmailServer ( )
109
106
this . manageCertificate ( )
110
- await this . manageStorage ( )
107
+ this . manageStorage ( )
111
108
this . manageFirewall ( )
112
109
this . manageFileSystem ( )
113
110
@@ -319,12 +316,12 @@ export class StacksCloud extends Stack {
319
316
} )
320
317
}
321
318
322
- async manageStorage ( ) {
319
+ manageStorage ( ) {
323
320
// the bucketName cannot contain the domainName because when it is changed,
324
321
// this resource needs to stay around/is retained. Hence, the domainName
325
322
// does not make much sense using as a (linking) identifier
326
323
327
- const publicBucket = await this . getOrCreateBucket ( )
324
+ const publicBucket = this . createBucket ( )
328
325
// for each redirect, create a bucket & redirect it to the APP_URL
329
326
config . dns . redirects ?. forEach ( ( redirect ) => {
330
327
// TODO: use string-ts function here instead
@@ -345,13 +342,13 @@ export class StacksCloud extends Stack {
345
342
} )
346
343
} )
347
344
348
- const privateBucket = await this . getOrCreateBucket ( 'private' )
345
+ const privateBucket = this . createBucket ( 'private' )
349
346
350
347
let logBucket : s3 . Bucket | undefined
351
348
if ( config . cloud . cdn ?. enableLogging ) {
352
349
logBucket = new s3 . Bucket ( this , 'LogBucket' , {
353
350
bucketName : `${ this . appName } -logs-${ appEnv } -${ timestamp } ` ,
354
- removalPolicy : RemovalPolicy . RETAIN ,
351
+ removalPolicy : RemovalPolicy . DESTROY ,
355
352
objectOwnership : s3 . ObjectOwnership . BUCKET_OWNER_PREFERRED ,
356
353
} )
357
354
}
@@ -522,8 +519,8 @@ export class StacksCloud extends Stack {
522
519
return { cdn, originAccessIdentity, cdnCachePolicy }
523
520
}
524
521
525
- async manageEmailServer ( ) {
526
- this . storage . emailBucket = await this . getOrCreateBucket ( 'email' )
522
+ manageEmailServer ( ) {
523
+ this . storage . emailBucket = this . createBucket ( 'email' )
527
524
528
525
const sesPrincipal = new iam . ServicePrincipal ( 'ses.amazonaws.com' )
529
526
const bucketPolicyStatement = new iam . PolicyStatement ( {
@@ -905,34 +902,34 @@ export class StacksCloud extends Stack {
905
902
}
906
903
}
907
904
908
- async getOrCreateBucket ( type ?: 'public' | 'private' | 'email' ) : Promise < s3 . Bucket | s3 . IBucket > {
909
- let bucketPrefix , existingBucketName
905
+ createBucket ( type ?: 'public' | 'private' | 'email' ) : s3 . Bucket {
906
+ let bucketPrefix
910
907
911
908
if ( type === 'private' ) {
912
909
bucketPrefix = `${ this . appName } -private-${ appEnv } -`
913
- existingBucketName = await getBucketWithPrefix ( bucketPrefix )
910
+ // existingBucketName = await getBucketWithPrefix(bucketPrefix)
914
911
915
- if ( existingBucketName )
916
- return s3 . Bucket . fromBucketArn ( this , 'PrivateBucket' , `arn:aws:s3:::${ existingBucketName } ` )
912
+ // if (existingBucketName)
913
+ // return s3.Bucket.fromBucketArn(this, 'PrivateBucket', `arn:aws:s3:::${existingBucketName}`)
917
914
918
915
return new s3 . Bucket ( this , 'PrivateBucket' , {
919
916
bucketName : `${ bucketPrefix } ${ timestamp } ` ,
920
917
versioned : true ,
921
- removalPolicy : RemovalPolicy . RETAIN ,
918
+ removalPolicy : RemovalPolicy . DESTROY ,
922
919
} )
923
920
}
924
921
925
922
if ( type === 'email' ) {
926
923
bucketPrefix = `${ this . appName } -email-${ appEnv } -`
927
- existingBucketName = await getBucketWithPrefix ( bucketPrefix )
924
+ // existingBucketName = await getBucketWithPrefix(bucketPrefix)
928
925
929
- if ( existingBucketName )
930
- return s3 . Bucket . fromBucketArn ( this , 'EmailServerBucket' , `arn:aws:s3:::${ existingBucketName } ` )
926
+ // if (existingBucketName)
927
+ // return s3.Bucket.fromBucketArn(this, 'EmailServerBucket', `arn:aws:s3:::${existingBucketName}`)
931
928
932
929
return new s3 . Bucket ( this , 'EmailServerBucket' , {
933
930
bucketName : `${ this . appName } -email-${ appEnv } -${ timestamp } ` ,
934
931
versioned : true ,
935
- removalPolicy : RemovalPolicy . RETAIN ,
932
+ removalPolicy : RemovalPolicy . DESTROY ,
936
933
lifecycleRules : [
937
934
{
938
935
id : '24h' ,
@@ -946,15 +943,15 @@ export class StacksCloud extends Stack {
946
943
}
947
944
948
945
bucketPrefix = `${ this . appName } -${ appEnv } -`
949
- existingBucketName = await getBucketWithPrefix ( bucketPrefix )
946
+ // existingBucketName = await getBucketWithPrefix(bucketPrefix)
950
947
951
- if ( existingBucketName )
952
- return s3 . Bucket . fromBucketArn ( this , 'PublicBucket' , `arn:aws:s3:::${ existingBucketName } ` )
948
+ // if (existingBucketName)
949
+ // return s3.Bucket.fromBucketArn(this, 'PublicBucket', `arn:aws:s3:::${existingBucketName}`)
953
950
954
951
return new s3 . Bucket ( this , 'PublicBucket' , {
955
952
bucketName : `${ bucketPrefix } ${ timestamp } ` ,
956
953
versioned : true ,
957
- removalPolicy : RemovalPolicy . RETAIN ,
954
+ removalPolicy : RemovalPolicy . DESTROY ,
958
955
} )
959
956
}
960
957
0 commit comments