Skip to content

Commit

Permalink
Add native compilation example
Browse files Browse the repository at this point in the history
  • Loading branch information
avishayp committed Dec 14, 2017
1 parent c2038c2 commit 9422aed
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 0 deletions.
7 changes: 7 additions & 0 deletions example_native_deps/.gitignore
@@ -0,0 +1,7 @@
# npm install
node_modules
package-lock.json

# serverless
.serverless
.requirements.zip
22 changes: 22 additions & 0 deletions example_native_deps/README.md
@@ -0,0 +1,22 @@
### native compilation example
Uses `dockerizePip` to deploy numpy-scipy-sklearn demo.

### test
As in other examples, use node version >= 6.

```
cd example_native_deps
npm install --prefix . serverless-python-requirements
sls deploy --verbose
sls invoke -f hello --verbose --log
```

...expected result:

```
{
"numpy": "1.13.3",
"scipy": "1.0.0",
"sklearn": "0.19.1"
}
```
13 changes: 13 additions & 0 deletions example_native_deps/handler.py
@@ -0,0 +1,13 @@
# must be called as we're using zipped requirements
try:
import unzip_requirements
except ImportError:
pass

import numpy
import scipy
import sklearn


def hello(event, context):
return {mod.__name__: mod.__version__ for mod in (numpy, scipy, sklearn)}
3 changes: 3 additions & 0 deletions example_native_deps/requirements.txt
@@ -0,0 +1,3 @@
numpy==1.13.3
scipy==1.0.0
sklearn==0.0
32 changes: 32 additions & 0 deletions example_native_deps/serverless.yml
@@ -0,0 +1,32 @@
service: sls-py-req-test

provider:
name: aws
runtime: python3.6

plugins:
- serverless-python-requirements

custom:
pythonRequirements:
# call `pip install` inside a container - useful for packages that have native dependencies (scipy et-al)
dockerizePip: true

# aws lambda has an after-extraction size limit - with native dependencies we pass the limit quickly
# zip the requirements and extract them on the fly (see handler.py)
zip: true

package:
# exclude everything...
exclude:
- '**/*'

# include - we have to explicitly list packages with native dependencies.
include:
- '*.py'
- 'numpy'
- 'scipy'

functions:
hello:
handler: handler.hello

0 comments on commit 9422aed

Please sign in to comment.