serverless-python-requirements
serverless-python-requirements copied to clipboard
Wrong version of packages installed when multiple python runtimes in same serverless config
Are you certain it's a bug?
- [X] Yes, it looks like a bug
Are you using the latest plugin release?
- [X] Yes, I'm using the latest plugin release
Is there an existing issue for this?
- [X] I have searched existing issues, it hasn't been reported yet
Issue description
I have a serverless config with functions that have multiple python versions (python3.7 and python3.8)
However, serverless-python-requirements is packaging python3.8 version of the packages for the python3.7 function. This is causing exceptions when the function is deployed to aws lambda:
Importing the numpy C-extensions failed. This error can happen for many reasons, often due to issues with your setup or how NumPy was installed.
...
Original error was: No module named 'numpy.core._multiarray_umath'
(The python 3.8 version of numpy cannot be run by python 3.7) When I separate the python3.7 functions and python3.8 functions into separate serverless files the problem goes away (but, that isn't very maintainable)
The issue seems to be cause by a single options.pythonBin shared between all functions
https://github.com/serverless/serverless-python-requirements/blob/e8b2e51c265792046bacc3946f22f7bd842c60e6/lib/pip.js#L149
(This would be fixed if each function had it's own pythonBin)
Service configuration (serverless.yml) content
service: minimal-service
provider:
name: aws
runtime: python3.8
region: us-west-2
package:
individually: true
functions:
function37:
handler: handle.handler
module: function37/src
runtime: python3.7
function38:
handler: handle.handler
module: function38/src
plugins:
- serverless-python-requirements
Command name and used flags
serverless package (or serverless deploy)
Command output
N/A
Environment information
Framework Core: 3.28.1 (local) 3.28.1 (global)
Plugin: 6.2.3
SDK: 4.3.2