1
1
#!/usr/bin/env node
2
2
import 'source-map-support/register'
3
3
import * as path from 'path'
4
+ import * as packageJson from '../package.json'
5
+
4
6
import { HttpApi } from '@aws-cdk/aws-apigatewayv2-alpha'
5
7
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'
7
9
import { CloudFrontAllowedMethods , CloudFrontWebDistribution , OriginAccessIdentity } from 'aws-cdk-lib/aws-cloudfront'
8
10
import { Function } from 'aws-cdk-lib/aws-lambda'
9
11
import { Code , LayerVersion , Runtime } from 'aws-cdk-lib/aws-lambda'
@@ -32,16 +34,21 @@ class NextStandaloneStack extends Stack {
32
34
...props ,
33
35
}
34
36
37
+ const depsPrefix = `${ packageJson . name } -${ packageJson . version } `
38
+
35
39
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` ,
37
42
} )
38
43
39
44
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` ,
41
47
} )
42
48
43
49
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` ,
45
52
} )
46
53
47
54
const serverLambda = new Function ( this , 'DefaultNextJs' , {
@@ -50,7 +57,7 @@ class NextStandaloneStack extends Stack {
50
57
} ) ,
51
58
runtime : Runtime . NODEJS_16_X ,
52
59
handler : config . customServerHandler ,
53
- layers : [ depsLayer , nextLayer ] ,
60
+ layers : [ depsLayer , sharpLayer , nextLayer ] ,
54
61
// No need for big memory as image handling is done elsewhere.
55
62
memorySize : 512 ,
56
63
timeout : Duration . seconds ( 15 ) ,
0 commit comments