Skip to content

Commit

Permalink
Capture source code changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Lepozepo committed Feb 21, 2020
1 parent e983a79 commit 2824260
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
6 changes: 6 additions & 0 deletions src/Lambda.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
Expand All @@ -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
};
Expand Down

0 comments on commit 2824260

Please sign in to comment.