How to import self made modules on lambda

Hello,

I want to create functions that will be used by many other lambdas.
So, my project structure is like that:

backend
└── libs
    ├── test
            ├── helper.py
    └── requirements.txt
└── services
    ├── test-api
            ├── .serverless
            ├── node_modules
            ├── app.py
            ├── package.json
            ├── package-lock.json
            ├── requirements.txt
            ├── serverless.yml
└── requirements.txt
└── serverless.common.yml

I want to share the code inside libs/serde/helper on test-api, so I installed serverless-python-requirements
And, I added to the serverless.yml of test-api:

plugins:
  - serverless-python-requirements
.....

But, when running my lambda test-api I receive the error:
ModuleNotFoundError: No module named 'libs'

So, how can I work with functions that are shared by multiple lambdas? What am I doing wrong?

I was facing the same problem today and finally i solved it but i’m not sure if i did it to complicated.

  1. i have a simple serverless project with 3 lambda’s each package as a module “individually”
  2. for the functions i want to reuse i built a python package (egg)
  3. then i created a lambda layer for the self-made package
  4. then i could import the package/modules in the lambda function

before i packed each lambda as a module i could import the functions from an “upper” folder, but after modularize them not anymore.

I did my steps along this doc


and also used this sample project https://github.com/bryantbiggs/repro-serverless-requirements/blob/master/sdk/setup.py

I cannot provide you my project like it is now, but if you need it as a whole i can strip out some stuff and then provide it to you; but maybe those parts already help you.