@@ -26,27 +26,22 @@ export class ComputeStack {
26
26
throw new Error ( 'The file system is missing. Please make sure it was created properly.' )
27
27
28
28
const cluster = new ecs . Cluster ( scope , 'StacksCluster' , {
29
+ clusterName : `${ props . slug } -${ props . appEnv } -web-server-cluster` ,
29
30
vpc,
30
31
} )
31
32
32
33
const taskDefinition = new ecs . FargateTaskDefinition ( scope , 'TaskDef' , {
33
34
memoryLimitMiB : 512 , // Match your Lambda memory size
34
35
cpu : 256 , // Choose an appropriate value
35
- portMappings : [ { containerPort : 80 } ] ,
36
36
} )
37
37
38
38
const container = taskDefinition . addContainer ( 'WebServerContainer' , {
39
39
image : ecs . ContainerImage . fromAsset ( p . frameworkPath ( 'server' ) ) ,
40
- // You can add environment variables, logging, etc., here
41
- } )
42
-
43
- container . addPortMappings ( {
44
- containerPort : 80 , // or whatever port your application listens on
45
- // hostPort: 80, // Optional: Specify if you need to map to a specific host port
46
- // protocol: ecs.Protocol.TCP, // Optional: Specify protocol, defaults to TCP
40
+ portMappings : [ { containerPort : 80 } ] ,
47
41
} )
48
42
49
43
const fargateService = new ecs_patterns . ApplicationLoadBalancedFargateService ( scope , 'FargateService' , {
44
+ serviceName : `${ props . slug } -${ props . appEnv } -fargate-service` ,
50
45
cluster,
51
46
taskDefinition,
52
47
desiredCount : 1 , // Start with 1 task instance
@@ -71,52 +66,30 @@ export class ComputeStack {
71
66
readOnly : false ,
72
67
} )
73
68
74
- // this.apiServer = new lambda.Function(scope, 'WebServer', {
75
- // functionName: `${props.slug}-${props.appEnv}-web-server`,
76
- // description: 'The web server for the Stacks application',
77
- // code: lambda.Code.fromAssetImage(p.frameworkPath('server')),
78
- // handler: lambda.Handler.FROM_IMAGE,
79
- // runtime: lambda.Runtime.FROM_IMAGE,
80
- // vpc,
81
- // memorySize: 512, // replace with your actual memory size
82
- // timeout: Duration.minutes(5), // replace with your actual timeout
83
- // logRetention: logs.RetentionDays.ONE_WEEK,
84
- // architecture: lambda.Architecture.ARM_64,
85
- // // filesystem: lambda.FileSystem.fromEfsAccessPoint(props.accessPoint, '/mnt/efs'),
86
- // })
87
-
88
69
const keysToRemove = [ '_HANDLER' , '_X_AMZN_TRACE_ID' , 'AWS_REGION' , 'AWS_EXECUTION_ENV' , 'AWS_LAMBDA_FUNCTION_NAME' , 'AWS_LAMBDA_FUNCTION_MEMORY_SIZE' , 'AWS_LAMBDA_FUNCTION_VERSION' , 'AWS_LAMBDA_INITIALIZATION_TYPE' , 'AWS_LAMBDA_LOG_GROUP_NAME' , 'AWS_LAMBDA_LOG_STREAM_NAME' , 'AWS_ACCESS_KEY' , 'AWS_ACCESS_KEY_ID' , 'AWS_SECRET_ACCESS_KEY' , 'AWS_SESSION_TOKEN' , 'AWS_LAMBDA_RUNTIME_API' , 'LAMBDA_TASK_ROOT' , 'LAMBDA_RUNTIME_DIR' , '_' ]
89
70
keysToRemove . forEach ( key => delete env [ key as EnvKey ] )
90
71
91
- // const secrets = new secretsmanager.Secret(scope, 'StacksSecrets', {
92
- // secretName: `${props.slug}-${props.appEnv}-secrets`,
93
- // description: 'Secrets for the Stacks application',
94
- // generateSecretString: {
95
- // secretStringTemplate: JSON.stringify(env),
96
- // generateStringKey: Object.keys(env).join(',').length.toString(),
97
- // },
98
- // })
99
-
100
- // secrets.grantRead(this.apiServer)
101
- // this.apiServer.addEnvironment('SECRETS_ARN', secrets.secretArn)
72
+ const secrets = new secretsmanager . Secret ( scope , 'StacksSecrets' , {
73
+ secretName : `${ props . slug } -${ props . appEnv } -secrets` ,
74
+ description : 'Secrets for the Stacks application' ,
75
+ generateSecretString : {
76
+ secretStringTemplate : JSON . stringify ( env ) ,
77
+ generateStringKey : Object . keys ( env ) . join ( ',' ) . length . toString ( ) ,
78
+ } ,
79
+ } )
102
80
103
- // this.apiServerUrl = new lambda.FunctionUrl(scope, 'StacksServerUrl', {
104
- // function: this.apiServer,
105
- // authType: lambda.FunctionUrlAuthType.NONE, // becomes a public API
106
- // cors: {
107
- // allowedOrigins: ['*'],
108
- // },
109
- // })
81
+ secrets . grantRead ( fargateService . taskDefinition . executionRole ! )
82
+ container . addEnvironment ( 'SECRETS_ARN' , secrets . secretArn )
110
83
111
84
const apiPrefix = 'api'
112
85
new Output ( scope , 'ApiUrl' , {
113
86
value : `https://${ props . domain } /${ apiPrefix } ` ,
114
87
description : 'The URL of the deployed application' ,
115
88
} )
116
89
117
- // new Output(scope, 'ApiVanityUrl', {
118
- // value: this.apiServerUrl.url ,
119
- // description: 'The Vanity URL of the deployed application',
120
- // })
90
+ new Output ( scope , 'ApiVanityUrl' , {
91
+ value : '' ,
92
+ description : 'The Vanity URL of the deployed application' ,
93
+ } )
121
94
}
122
95
}
0 commit comments