Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working when using module in Python #1465

Closed
mebibou opened this issue Jun 1, 2022 · 4 comments
Closed

Not working when using module in Python #1465

mebibou opened this issue Jun 1, 2022 · 4 comments

Comments

@mebibou
Copy link
Contributor

mebibou commented Jun 1, 2022

Bug Report

Current Behavior

When running sls offline and accessing the url I have the following error:

Traceback (most recent call last):
  File "/[src]/node_modules/serverless-offline/dist/lambda/handler-runner/python-runner/invoke.py", line 76, in <module>

    module = import_module(args.handler_path.replace(os.sep, '.'))
  File "/opt/miniconda3/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'handler'

Sample Code

  • file: serverless.yml
service: my-service

plugins:
  - serverless-offline

provider:
  runtime: python3.9
  stage: dev

functions:
  hello:
    handler: handler.hello
    module: my_module
    timeout: 30
    events:
      - http:
          path: /hello
          method: get
          cors: true
  • file: my_module/handler.py
def handler(*args):
    print('hello')

Expected behavior/code

Should work just line when not using the module in serverless

Environment

  • serverless version: 2.66.2
  • serverless-offline version: 8.8.0
  • node.js version: 12.22.6
  • OS: MacOs 12.4
Your Environment Information ---------------------------
     Operating System:          darwin
     Node Version:              12.22.6
     Framework Version:         2.66.2
     Plugin Version:            5.5.1
     SDK Version:               4.3.0
     Components Version:        3.18.1

optional, if you are using any of the following frameworks to invoke handlers

  • python version: 3.9

Possible Solution

I'm guessing when trying to find handler it should take into account the module if specified but it currently doesn't?

Additional context/Screenshots

@mebibou
Copy link
Contributor Author

mebibou commented Jun 1, 2022

Note: it might be the same kind of error as #1381, but I am using a module while that other issue is not but using deep handler, so the resolution might be different

@dnalborczyk
Copy link
Collaborator

#1381 was reverted in v8.8.0, if you are sure that you are using that version your issue should be a different one.

if you could digg into this problem and put up a PR that would be great. if not, a repro would be very helpful as well.

@mebibou
Copy link
Contributor Author

mebibou commented Jun 2, 2022

@dnalborczyk ok created a PR based on what I modified locally to make it work. Not sure if it should be that simple, but it works

@dnalborczyk
Copy link
Collaborator

I'm closing this @mebibou I hope that's ok, as this is not a supported config feature by serverless itself. #1467

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants