From e3775512efdd43e0b8558144d1ed01c994244aad Mon Sep 17 00:00:00 2001 From: Matthew Amos <35695811+blackmamo@users.noreply.github.com> Date: Wed, 17 Apr 2019 16:23:31 +0100 Subject: [PATCH 1/3] Junction don't copy Copying the files on windows is very slow and can be avoided by using junctions --- lib/pip.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/pip.js b/lib/pip.js index 3da432af..323a92fb 100644 --- a/lib/pip.js +++ b/lib/pip.js @@ -610,10 +610,9 @@ function installAllRequirements() { !fse.existsSync(symlinkPath) && reqsInstalledAt != symlinkPath ) { - // Windows can't symlink so we have to copy on Windows, - // it's not as fast, but at least it works + // Windows can't symlink so we have to use junction on Windows if (process.platform == 'win32') { - fse.copySync(reqsInstalledAt, symlinkPath); + fse.symlink(reqsInstalledAt, symlinkPath, 'junction'); } else { fse.symlink(reqsInstalledAt, symlinkPath); } From 62b391179d1df4cc6f38b3e8b76d10aa3694e7b4 Mon Sep 17 00:00:00 2001 From: Matthew Amos <35695811+blackmamo@users.noreply.github.com> Date: Wed, 17 Apr 2019 16:37:03 +0100 Subject: [PATCH 2/3] Advice to reduce build times This advice saved me a lot of time --- README.md | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 11e8ae5d..8ef2d991 100644 --- a/README.md +++ b/README.md @@ -174,7 +174,7 @@ custom: strip: false ``` -### Lamba Layer +### Lambda Layer Another method for dealing with large dependencies is to put them into a [Lambda Layer](https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html). Simply add the `layer` option to the configuration. @@ -439,6 +439,35 @@ zipinfo .serverless/xxx.zip ``` (If you can't see the library, you might need to adjust your package include/exclude configuration in `serverless.yml`.) +## Optimising packaging time + +If you wish to exclude most of the files in your project, and only include the source files of your lambdas and their dependencies you may well use an approach like this: + +```yaml +package: + individually: false + include: + - "./src/lambda_one/**" + - "./src/lambda_two/**" + exclude: + - "**" +``` + +This will be very slow. Serverless adds a default '"**"' include. If you are using the 'cacheLocation' parameter to this plugin, this will result in all of the cached files' names being loaded and then subsequently discarded because of the exclude pattern. To avoid this happening you can add a negated include pattern, as is observed in https://github.com/serverless/serverless/pull/5825. + +Use this approach instead: + +```yaml +package: + individually: false + include: + - "!./**" + - "./src/lambda_one/**" + - "./src/lambda_two/**" + exclude: + - "**" +``` + ## Contributors * [@dschep](https://github.com/dschep) - Lead developer & maintainer * [@azurelogic](https://github.com/azurelogic) - logging & documentation fixes From a018f5d8ffb42e1d3da20ecefda4b4519fca19fe Mon Sep 17 00:00:00 2001 From: Matthew Amos <35695811+blackmamo@users.noreply.github.com> Date: Wed, 17 Apr 2019 16:38:00 +0100 Subject: [PATCH 3/3] Wrong quotes --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8ef2d991..37254fd3 100644 --- a/README.md +++ b/README.md @@ -453,7 +453,7 @@ package: - "**" ``` -This will be very slow. Serverless adds a default '"**"' include. If you are using the 'cacheLocation' parameter to this plugin, this will result in all of the cached files' names being loaded and then subsequently discarded because of the exclude pattern. To avoid this happening you can add a negated include pattern, as is observed in https://github.com/serverless/serverless/pull/5825. +This will be very slow. Serverless adds a default `"**"` include. If you are using the `cacheLocation` parameter to this plugin, this will result in all of the cached files' names being loaded and then subsequently discarded because of the exclude pattern. To avoid this happening you can add a negated include pattern, as is observed in https://github.com/serverless/serverless/pull/5825. Use this approach instead: