File tree 3 files changed +26
-12
lines changed
3 files changed +26
-12
lines changed Original file line number Diff line number Diff line change @@ -32,9 +32,16 @@ import requirements
32
32
import requests
33
33
` ` `
34
34
35
- # # Limitations
35
+ # # Cross compiling!
36
+ Compiling non-pure-Python modules is supported on MacOS via the use of Docker
37
+ and the [docker-lambda](https://github.com/lambci/docker-lambda) image.
38
+ To enable docker usage, add the following to your `serverless.yml` :
39
+ ` ` ` yaml
40
+ custom:
41
+ dockerizePip: true
42
+ ` ` `
36
43
37
- * MacOS & Windows: For now this only works with pure Python modules unless running serverless on the same architeture as AWS (x86_64 Linux).
44
+ # # Limitations
38
45
* if using the `package` directive in `serverless.yml` ensure that `.requirements` and `requirements.py` are included.
39
46
40
47
Original file line number Diff line number Diff line change @@ -19,22 +19,29 @@ class ServerlessPythonRequirements {
19
19
} ;
20
20
21
21
packRequirements ( ) {
22
- const requirementsFile = path . join ( this . serverless . config . servicePath , 'requirements.txt' ) ;
23
-
24
- if ( ! fse . existsSync ( requirementsFile ) ) {
22
+ if ( ! fse . existsSync ( path . join ( this . serverless . config . servicePath , 'requirements.txt' ) ) ) {
25
23
return BbPromise . resolve ( ) ;
26
24
}
27
25
28
26
this . serverless . cli . log ( 'Packaging required Python packages...' ) ;
29
27
30
28
return new BbPromise ( ( resolve , reject ) => {
31
- const res = child_process . spawnSync ( 'pip' , [
29
+ let cmd = 'pip' ;
30
+ let options = [
32
31
'install' ,
33
- '-t' ,
34
- path . join ( this . serverless . config . servicePath , '.requirements' ) ,
35
- '-r' ,
36
- requirementsFile ,
37
- ] ) ;
32
+ '-t' , '.requirements' ,
33
+ '-r' , 'requirements.txt' ,
34
+ ] ;
35
+ if ( this . serverless . service . custom &&
36
+ this . serverless . service . custom . dockerizePip ) {
37
+ cmd = 'docker' ;
38
+ options = [
39
+ 'run' , '--rm' ,
40
+ '-v' , `${ this . serverless . config . servicePath } :/var/task:z` ,
41
+ 'lambci/lambda:build-python2.7' , 'pip' ,
42
+ ] . concat ( options ) ;
43
+ }
44
+ const res = child_process . spawnSync ( cmd , options ) ;
38
45
if ( res . error ) {
39
46
return reject ( res . error ) ;
40
47
}
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " serverless-python-requirements" ,
3
- "version" : " 1.1 .0" ,
3
+ "version" : " 1.2 .0" ,
4
4
"engines" : {
5
5
"node" : " >=4.0"
6
6
},
You can’t perform that action at this time.
0 commit comments