serverless / serverless-python-requirements

⚡️🐍📦 Serverless plugin to bundle Python packages

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Wrong version of packages installed when multiple python runtimes in same serverless config

svonderohe opened this issue · comments

Are you certain it's a bug?

  • Yes, it looks like a bug

Are you using the latest plugin release?

  • Yes, I'm using the latest plugin release

Is there an existing issue for this?

  • 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

const pipCmd = [options.pythonBin, '-m', 'pip', 'install'];

(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