Skip to content
This repository was archived by the owner on Oct 24, 2025. It is now read-only.
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
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

[![npm](https://nodei.co/npm/serverless-python-requirements.png?downloads=true&downloadRank=true)](https://www.npmjs.com/package/serverless-python-requirements)

A Serverless v1.0 plugin to automatically bundle dependencies from
A Serverless v1.0 plugin to automatically bundle dependencies from
`requirements.txt` and make them available in your `PYTHONPATH`.


Expand Down Expand Up @@ -34,6 +34,7 @@ custom:
dockerizePip: true
```


## Dealing with Lambda's size limitations
To help deal with potentially large dependencies (for example: `numpy`, `scipy`
and `scikit-learn`) there is support for compressing the libraries. This does
Expand Down Expand Up @@ -67,6 +68,21 @@ behind to speed things up on subsequent deploys. To clean them up, run
`sls requirements clean`. You can also create them (and `unzip_requirements` if
using zip support) manually with `sls requirements install`.


## Updating to python 3.6

This requires an update to your serverless.yml:

```
provider:
name: aws
runtime: python3.6
```

And be sure to clean up `.requirements` or `requirements.zip` if they exist as
python2.7 and python3.6 code can't coexist.


## Credit
This plugin is influenced by
[serverless-wsgi](https://github.com/logandk/serverless-wsgi) from
Expand Down
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ class ServerlessPythonRequirements {
return BbPromise.resolve();
}

this.serverless.cli.log('Installing required Python packages...');
const runtime = this.serverless.service.provider.runtime;
this.serverless.cli.log(`Installing required Python packages for runtime ${runtime}...`);

return new BbPromise((resolve, reject) => {
let cmd, options;
const pipCmd = [
'pip', '--isolated', 'install',
runtime, '-m', 'pip', '-v', '--isolated', 'install',
'-t', '.requirements', '-r', 'requirements.txt',
];
if (this.custom.dockerizePip) {
Expand All @@ -47,7 +48,7 @@ class ServerlessPythonRequirements {
'run', '--rm',
'-u', process.getuid() + ':' + process.getgid(),
'-v', `${this.serverless.config.servicePath}:/var/task:z`,
'lambci/lambda:build-python2.7',
`lambci/lambda:build-${runtime}`,
];
options.push(...pipCmd)
} else {
Expand Down