Skip to content

Speed up windows packaging #347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions lib/pip.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this require any extra user permissions? I recall something about that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is my understanding that junctions only require the normal file creation permissions. When created they use fully qualified paths and can only link to directories in the same NTFS filesystem.

The admin permissions are required for a full symlink because this has more serious security complications.

The only potential problem I can see is if someone has set up their cache directory and the serverless directory on separate file systems. In that case the junction operation would fail. I could add this note to the readme, but it may be a lot of noise for an unlikely setup.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, very cool. I thought junctions were symlinks. Thanks for the clarification.

} else {
fse.symlink(reqsInstalledAt, symlinkPath);
}
Expand Down