From 2824260d54678157a4f83c275b16d3b2a6ce7070 Mon Sep 17 00:00:00 2001 From: Marcelo Reyna Date: Fri, 21 Feb 2020 11:42:58 -0800 Subject: [PATCH] Capture source code changes --- package-lock.json | 5 +++++ package.json | 1 + src/Lambda.js | 6 ++++++ 3 files changed, 12 insertions(+) diff --git a/package-lock.json b/package-lock.json index 2466d39..8ec3ba6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11168,6 +11168,11 @@ } } }, + "sha256-file": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/sha256-file/-/sha256-file-1.0.0.tgz", + "integrity": "sha512-nqf+g0veqgQAkDx0U2y2Tn2KWyADuuludZTw9A7J3D+61rKlIIl9V5TS4mfnwKuXZOH9B7fQyjYJ9pKRHIsAyg==" + }, "shebang-command": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", diff --git a/package.json b/package.json index 39a6f01..b8c0091 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "lodash": "^4.17.15", "mime": "^2.4.4", "recursive-readdir-sync": "^1.0.6", + "sha256-file": "^1.0.0", "uuid": "^3.4.0" }, "devDependencies": { diff --git a/src/Lambda.js b/src/Lambda.js index 76ff8ee..5d5bd8a 100644 --- a/src/Lambda.js +++ b/src/Lambda.js @@ -11,6 +11,8 @@ import p from 'path'; import cp from 'child_process'; import readdirp from 'recursive-readdir-sync'; import fs from 'fs'; +import uuid from 'uuid/v3'; +import sha256File from 'sha256-file'; import WebsocketApi from './WebsocketApi'; export default class Lambda extends pulumi.ComponentResource { @@ -83,11 +85,14 @@ export default class Lambda extends pulumi.ComponentResource { this.layer = layer; const lambdaAssetMap = {}; + const sourceCodeHashObj = {}; readdirp(source).forEach((srcObject) => { if (srcObject.includes('node_modules')) return; lambdaAssetMap[p.relative(source, srcObject)] = new pulumi.asset.FileAsset(srcObject); + sourceCodeHashObj[p.relative(source, srcObject)] = sha256File(srcObject); }); + const sourceCodeHash = uuid(JSON.stringify(sourceCodeHashObj), uuid.URL); const lambdaSrc = new aws.s3.BucketObject(`${name}-lambdaSrc`, { bucket: srcBucket.bucket, source: new pulumi.asset.AssetArchive(lambdaAssetMap), @@ -105,6 +110,7 @@ export default class Lambda extends pulumi.ComponentResource { layers: [layer, ...layers], s3Bucket: srcBucket.bucket, s3Key: lambdaSrc.key, + sourceCodeHash, role: role.arn, publish: true, // Required for provisioned concurrency };