-
Notifications
You must be signed in to change notification settings - Fork 293
invoke local issue when "module" is defined #520
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
Comments
warkaround : this can be fixed in the
|
Having the same issue, have you been able to find any other solutions? |
temporary try my workaround #520 (comment) |
I'm also affected by this issue. Removing the |
I've found another temporary workaround using environment variables in functions:
LambdaTestFunction:
handler: ${env:HANDLER_PATH_PREFIX, ""}handler.handler
module: src/test_lambda
...
...
package:
individually: true When I invoke locally, I use the following command: HANDLER_PATH_PREFIX=src/test_lambda/ LOCAL=true ./node_modules/serverless/bin/serverless.js invoke local -f LambdaTest -p ./tests/resources/base_event.yml I've tested local and remote invocations and I can confirm it's working as expected. |
Thanks @sndrsnk. This works. But I then have a problem with importing modules from alongside handler.py. I find that they either work in local or lambda, depending on my syntax. As a workaround, I have to do this:
Note that IS_LOCAL is automatically set by serverless framework - you don't need to make it yourself. Python isn't my fave language, so I'm probably doing something dumb. Or is this required? (I tried doing |
@jamesoflol You're welcome, and thanks for raising the issue regarding relative imports. I tested it on my end and can confirm that I'm experiencing the same issue. I did some research and found a really nice workaround here. Simply add the following block of code to your package's import os
import sys
sys.path.append(os.path.dirname(os.path.realpath(__file__)))
Hope it helps! |
@sndrsnk Thanks for sharing! Here' another workaround by setting the
|
The provided workaround works great for functions without an import of an external package. |
I'm unable to invoke my function locally when I use the module functionality:
severless.yml
invoke local :
serverless invoke local -f my_function
got error :
ModuleNotFoundError: No module named 'my_function'
The text was updated successfully, but these errors were encountered: