Skip to content
This repository was archived by the owner on Feb 1, 2025. It is now read-only.

Commit 8458d70

Browse files
author
Bender
committed
ref(cdk): use layer description and custom hash to avoid re-uploads
1 parent 134d90c commit 8458d70

File tree

4 files changed

+582
-574
lines changed

4 files changed

+582
-574
lines changed

cdk/app.ts

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#!/usr/bin/env node
22
import 'source-map-support/register'
33
import * as path from 'path'
4+
import * as packageJson from '../package.json'
5+
46
import { HttpApi } from '@aws-cdk/aws-apigatewayv2-alpha'
57
import { HttpLambdaIntegration } from '@aws-cdk/aws-apigatewayv2-integrations-alpha'
6-
import { App, CfnOutput, Duration, RemovalPolicy, Stack, StackProps, SymlinkFollowMode } from 'aws-cdk-lib'
8+
import { App, AssetHashType, CfnOutput, Duration, RemovalPolicy, Stack, StackProps, SymlinkFollowMode } from 'aws-cdk-lib'
79
import { CloudFrontAllowedMethods, CloudFrontWebDistribution, OriginAccessIdentity } from 'aws-cdk-lib/aws-cloudfront'
810
import { Function } from 'aws-cdk-lib/aws-lambda'
911
import { Code, LayerVersion, Runtime } from 'aws-cdk-lib/aws-lambda'
@@ -32,16 +34,21 @@ class NextStandaloneStack extends Stack {
3234
...props,
3335
}
3436

37+
const depsPrefix = `${packageJson.name}-${packageJson.version}`
38+
3539
const depsLayer = new LayerVersion(this, 'DepsLayer', {
36-
code: Code.fromAsset(config.dependenciesZipPath),
40+
code: Code.fromAsset(config.dependenciesZipPath, { assetHashType: AssetHashType.CUSTOM, assetHash: depsPrefix }),
41+
layerVersionName: `${depsPrefix}-deps`,
3742
})
3843

3944
const sharpLayer = new LayerVersion(this, 'SharpLayer', {
40-
code: Code.fromAsset(config.sharpLayerZipPath),
45+
code: Code.fromAsset(config.sharpLayerZipPath, { assetHashType: AssetHashType.CUSTOM, assetHash: depsPrefix }),
46+
layerVersionName: `${depsPrefix}-sharp`,
4147
})
4248

4349
const nextLayer = new LayerVersion(this, 'NextLayer', {
44-
code: Code.fromAsset(config.nextLayerZipPath),
50+
code: Code.fromAsset(config.nextLayerZipPath, { assetHashType: AssetHashType.CUSTOM, assetHash: depsPrefix }),
51+
layerVersionName: `${depsPrefix}-next`,
4552
})
4653

4754
const serverLambda = new Function(this, 'DefaultNextJs', {
@@ -50,7 +57,7 @@ class NextStandaloneStack extends Stack {
5057
}),
5158
runtime: Runtime.NODEJS_16_X,
5259
handler: config.customServerHandler,
53-
layers: [depsLayer, nextLayer],
60+
layers: [depsLayer, sharpLayer, nextLayer],
5461
// No need for big memory as image handling is done elsewhere.
5562
memorySize: 512,
5663
timeout: Duration.seconds(15),

cdk/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"strict": true,
88
"noImplicitAny": true,
99
"strictNullChecks": true,
10+
"resolveJsonModule": true,
1011
"noImplicitThis": true,
1112
"alwaysStrict": true,
1213
"noUnusedLocals": false,

lib/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export const replaceVersionInCommonFiles = (oldVersion: string, newVersion: stri
161161
'**/__init__.py',
162162
],
163163
from: [
164-
/\"version\":(.*)"\d+\.\d+\.\d+"/g, // little more generic to allow for incorrect version to be replaced
164+
/\"version\":(.*)"\d+\.\d+\.\d+"/, // little more generic to allow for incorrect version to be replaced
165165
`"version": "${oldVersion}"`, // npm/php style
166166
`"version":"${oldVersion}"`, // uglified npm/php style
167167
`version = "${oldVersion}"`, // python style

0 commit comments

Comments
 (0)