Skip to content

Commit 3cc6fe3

Browse files
committed
fix(cdk): include layer dependencies in checksum
Otherwise the checksum does not change (and thus a new layer will not be deployed) in case only the dependencies to be installed are changed.
1 parent 4bc8fde commit 3cc6fe3

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

cdk/helpers/lambdas/checksumOfFiles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const checkSumOfFiles = async (files: string[]): Promise<string> => {
1212
return checksum
1313
}
1414

15-
const checkSumOfStrings = (strings: string[]): string => {
15+
export const checkSumOfStrings = (strings: string[]): string => {
1616
const hash = crypto.createHash('sha1')
1717
hash.update(strings.join(''))
1818
return hash.digest('hex')

cdk/helpers/lambdas/packLayer.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { copyFile, mkdir, readFile, rm, writeFile } from 'fs/promises'
44
import { glob } from 'glob'
55
import path from 'path'
66
import { ZipFile } from 'yazl'
7-
import { checkSumOfFiles } from './checksumOfFiles.js'
7+
import { checkSumOfFiles, checkSumOfStrings } from './checksumOfFiles.js'
88

99
export type PackedLayer = { layerZipFile: string; hash: string }
1010

@@ -58,8 +58,6 @@ export const packLayer = async ({
5858
const packageLock = path.join(nodejsDir, 'package-lock.json')
5959
await copyFile(packageLockJsonFile, packageLock)
6060

61-
const hash = await checkSumOfFiles([packageJSON, packageLock])
62-
6361
await new Promise<void>((resolve, reject) => {
6462
const [cmd, ...args] = [
6563
'npm',
@@ -103,6 +101,9 @@ export const packLayer = async ({
103101

104102
return {
105103
layerZipFile: zipFileName,
106-
hash,
104+
hash: checkSumOfStrings([
105+
JSON.stringify(dependencies),
106+
await checkSumOfFiles([packageJSON, packageLock]),
107+
]),
107108
}
108109
}

0 commit comments

Comments
 (0)