Skip to content

Commit 873ea3e

Browse files
committed
chore: wip
1 parent 45d5387 commit 873ea3e

File tree

5 files changed

+23
-60
lines changed

5 files changed

+23
-60
lines changed

.stacks/core/cloud/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@
5454
"prepublishOnly": "bun run build"
5555
},
5656
"peerDependencies": {
57-
"@aws-lambda-powertools/logger": "^1.14.0",
58-
"@aws-lambda-powertools/metrics": "^1.14.0",
59-
"@aws-lambda-powertools/tracer": "^1.14.0",
6057
"@aws-sdk/client-cloudformation": "^3.435.0",
6158
"@aws-sdk/client-cloudfront": "^3.435.0",
6259
"@aws-sdk/client-cloudwatch-logs": "^3.435.0",

.stacks/core/cloud/src/cloud/cdn.ts

Lines changed: 22 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ export class CdnStack extends NestedStack {
4646
apiCachePolicy: cloudfront.CachePolicy | undefined
4747
vanityUrl!: string
4848
apiVanityUrl!: string
49+
props: ResourceNestedStackProps
4950

5051
constructor(scope: Construct, props: ResourceNestedStackProps) {
5152
super(scope, 'Cdn', props)
53+
this.props = props
5254
// ...
5355
const originAccessIdentity = new cloudfront.OriginAccessIdentity(this, 'OAI')
5456

@@ -65,7 +67,7 @@ export class CdnStack extends NestedStack {
6567

6668
// Fetch the timestamp from SSM Parameter Store
6769
const timestampParam = ssm.StringParameter.fromSecureStringParameterAttributes(this, 'TimestampParam', {
68-
parameterName: `/${props.appName.toLowerCase()}/timestamp`,
70+
parameterName: `/${this.props.appName.toLowerCase()}/timestamp`,
6971
version: 1,
7072
})
7173

@@ -75,14 +77,14 @@ export class CdnStack extends NestedStack {
7577
if (!timestamp) {
7678
timestamp = new Date().getTime().toString()
7779
new ssm.StringParameter(this, 'TimestampParam', {
78-
parameterName: `/${props.appName.toLowerCase()}/timestamp`,
80+
parameterName: `/${this.props.appName.toLowerCase()}/timestamp`,
7981
stringValue: timestamp,
8082
})
8183
}
8284

8385
new route53.ARecord(this, 'AliasRecord', {
84-
recordName: props.domain,
85-
zone: props.zone,
86+
recordName: this.props.domain,
87+
zone: this.props.zone,
8688
target: route53.RecordTarget.fromAlias(new targets.CloudFrontTarget(this.cdn)),
8789
})
8890

@@ -92,7 +94,7 @@ export class CdnStack extends NestedStack {
9294
// this needs to have partialAppKey & timestamp to ensure it is unique, because there is a chance that during testing, you deploy
9395
// the same app many times using the same app key. Since Origin Request (Lambda@Edge) functions are replicated functions, the
9496
// deletion process takes a long time. This is to ensure that the function is always unique in cases of quick recreations.
95-
functionName: `${props.appName}-${props.appEnv}-origin-request-${props.partialAppKey}-${timestamp}`,
97+
functionName: `${this.props.appName}-${this.props.appEnv}-origin-request-${this.props.partialAppKey}-${timestamp}`,
9698
description: 'The Stacks Origin Request function that prettifies URLs',
9799
runtime: lambda.Runtime.NODEJS_18_X,
98100
handler: 'dist/origin-request.handler',
@@ -110,21 +112,21 @@ export class CdnStack extends NestedStack {
110112
cfnOriginRequestFunction.applyRemovalPolicy(RemovalPolicy.RETAIN)
111113

112114
const cdn = new cloudfront.Distribution(this, 'Distribution', {
113-
domainNames: [props.domain],
115+
domainNames: [this.props.domain],
114116
defaultRootObject: 'index.html',
115117
comment: `CDN for ${config.app.url}`,
116-
certificate: props.certificate,
118+
certificate: this.props.certificate,
117119
enableLogging: true,
118-
logBucket: props.logBucket,
120+
logBucket: this.props.logBucket,
119121
httpVersion: cloudfront.HttpVersion.HTTP2_AND_3,
120122
priceClass: cloudfront.PriceClass.PRICE_CLASS_ALL,
121123
enabled: true,
122124
minimumProtocolVersion: cloudfront.SecurityPolicyProtocol.TLS_V1_2_2021,
123-
webAclId: props.firewall.attrArn,
125+
webAclId: this.props.firewall.attrArn,
124126
enableIpv6: true,
125127

126128
defaultBehavior: {
127-
origin: new origins.S3Origin(props.storage.publicBucket, {
129+
origin: new origins.S3Origin(this.props.storage.publicBucket, {
128130
originAccessIdentity: this.originAccessIdentity,
129131
}),
130132
edgeLambdas: [
@@ -156,9 +158,9 @@ export class CdnStack extends NestedStack {
156158
// setup the www redirect
157159
// Create a bucket for www.yourdomain.com and configure it to redirect to yourdomain.com
158160
const wwwBucket = new s3.Bucket(this, 'WwwBucket', {
159-
bucketName: `www.${props.domain}`,
161+
bucketName: `www.${this.props.domain}`,
160162
websiteRedirect: {
161-
hostName: props.domain,
163+
hostName: this.props.domain,
162164
protocol: s3.RedirectProtocol.HTTPS,
163165
},
164166
removalPolicy: RemovalPolicy.DESTROY,
@@ -167,8 +169,8 @@ export class CdnStack extends NestedStack {
167169

168170
// Create a Route53 record for www.yourdomain.com
169171
new route53.ARecord(this, 'WwwAliasRecord', {
170-
recordName: `www.${props.domain}`,
171-
zone: props.zone,
172+
recordName: `www.${this.props.domain}`,
173+
zone: this.props.zone,
172174
target: route53.RecordTarget.fromAlias(new targets.BucketWebsiteTarget(wwwBucket)),
173175
})
174176

@@ -251,57 +253,21 @@ export class CdnStack extends NestedStack {
251253
}
252254

253255
deployApi() {
254-
const layer = new lambda.LayerVersion(this, 'BunLambdaLayer', {
255-
code: lambda.Code.fromAsset(p.projectStoragePath('framework/cloud/bun-lambda-layer.zip')),
256-
compatibleRuntimes: [lambda.Runtime.PROVIDED_AL2],
257-
compatibleArchitectures: [lambda.Architecture.ARM_64],
258-
license: 'MIT',
259-
description: 'Bun is an incredibly fast JavaScript runtime, bundler, transpiler, and package manager.',
260-
})
261-
262256
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', '_']
263257
keysToRemove.forEach(key => delete env[key as EnvKey])
264258

265259
const secrets = new secretsmanager.Secret(this, 'StacksSecrets', {
266-
secretName: `${props.appName}-${props.appEnv}-secrets`,
260+
secretName: `${this.props.appName}-${this.props.appEnv}-secrets`,
267261
description: 'Secrets for the Stacks application',
268262
generateSecretString: {
269263
secretStringTemplate: JSON.stringify(env),
270264
generateStringKey: Object.keys(env).join(',').length.toString(),
271265
},
272266
})
273267

274-
const functionName = `${props.appName}-${props.appEnv}-server`
275-
const serverFunction = new lambda.Function(this, 'StacksServer', {
276-
functionName,
277-
description: 'The Stacks Server',
278-
memorySize: 512,
279-
vpc: props.vpc,
280-
filesystem: lambda.FileSystem.fromEfsAccessPoint(props.storage.accessPoint!, '/mnt/efs'),
281-
timeout: Duration.seconds(30),
282-
tracing: lambda.Tracing.ACTIVE,
283-
code: lambda.Code.fromAsset(p.projectStoragePath('framework/cloud/api.zip'), {
284-
assetHash: this.node.tryGetContext('serverFunctionCodeHash'),
285-
assetHashType: AssetHashType.CUSTOM,
286-
}),
287-
handler: 'server.fetch',
288-
runtime: lambda.Runtime.PROVIDED_AL2,
289-
architecture: lambda.Architecture.ARM_64,
290-
layers: [layer],
291-
})
292-
293-
secrets.grantRead(serverFunction)
294-
serverFunction.addEnvironment('SECRETS_ARN', secrets.secretArn)
295-
296-
const api = new lambda.FunctionUrl(this, 'StacksServerUrl', {
297-
function: serverFunction,
298-
authType: lambda.FunctionUrlAuthType.NONE, // becomes a public API
299-
cors: {
300-
allowedOrigins: ['*'],
301-
},
302-
})
268+
const functionName = `${this.props.appName}-${this.props.appEnv}-server`
303269

304-
this.apiVanityUrl = api.url
270+
// this.apiVanityUrl = api.url
305271
}
306272

307273
apiBehaviorOptions(): Record<string, cloudfront.BehaviorOptions> {
@@ -333,7 +299,7 @@ export class CdnStack extends NestedStack {
333299
docsBehaviorOptions(): Record<string, cloudfront.BehaviorOptions> {
334300
return {
335301
'/docs': {
336-
origin: new origins.S3Origin(props.storage.publicBucket, {
302+
origin: new origins.S3Origin(this.props.storage.publicBucket, {
337303
originAccessIdentity: this.originAccessIdentity,
338304
originPath: '/docs',
339305
}),
@@ -344,7 +310,7 @@ export class CdnStack extends NestedStack {
344310
cachePolicy: cloudfront.CachePolicy.CACHING_OPTIMIZED,
345311
},
346312
'/docs/*': {
347-
origin: new origins.S3Origin(props.storage.publicBucket, {
313+
origin: new origins.S3Origin(this.props.storage.publicBucket, {
348314
originAccessIdentity: this.originAccessIdentity,
349315
originPath: '/docs',
350316
}),
@@ -388,7 +354,7 @@ export class CdnStack extends NestedStack {
388354

389355
this.apiCachePolicy = new cloudfront.CachePolicy(this, 'ApiCachePolicy', {
390356
comment: 'Stacks API Cache Policy',
391-
cachePolicyName: `${props.appName}-${props.appEnv}-api-cache-policy`,
357+
cachePolicyName: `${this.props.appName}-${this.props.appEnv}-api-cache-policy`,
392358
// minTtl: config.cloud.cdn?.minTtl ? Duration.seconds(config.cloud.cdn.minTtl) : undefined,
393359
defaultTtl: Duration.seconds(0),
394360
cookieBehavior: cloudfront.CacheCookieBehavior.none(),

.stacks/core/cloud/src/cloud/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export class Stacks extends Stack {
1717
constructor(scope: Construct, id: string, props: EnvProps) {
1818
super(scope, id, props)
1919

20+
// please beware: be careful changing the order of the stacks creation below
2021
new StorageStack(this, props)
2122
new CdnStack(this, props)
2223
new DocsStack(this, props)

.stacks/ide/dictionary.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ pluginutils
196196
pnpm
197197
polacek
198198
postcssrc
199-
powertools
200199
prefetch
201200
prepublishing
202201
procfile

bun.lockb

-25.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)