Hi, I've run into an issue deploying a python lamb...
# help
k
Hi, I've run into an issue deploying a python lambda with SST - this lambda used to work when deployed with Serverless framework so I'm assuming there's a config or an "include" I'm missing somewhere. This function has 2 files:
handler.py
and
service.py
The
handler.py
imports the
service.py
as normal (
import service
) so that it can delegate the work off to that service. The issue is that when running with
npx sst start
and in the aws console they both error with
"ModuleNotFoundError: No module named 'service'",
I made a test to replicate the issue from SST code:
Copy code
new sst.Function(this, "testFunc", {
      handler: "services/test/handler.process_job",
      srcPath: "src",
      layers: [dbDriverLayer],
      role: functionRole,
      tracing: Tracing.ACTIVE
    });
However, if I create a function within aws or upload my own package not through sst, the exact same code works fine (see attached image). Any ideas on what SST is doing differently to package and deploy lambdas that would break the python imports?
t
Is service.py inside
src
f
@Kyle Boucher can you also share how you are importing
servicer
?
k
@thdxr You can see the file structure in the photos. @Frank
import service
But here's the code for handler.py and service.py
t
Can you try setting srcPath to
services/test/
and handler to
handler.process_job
k
I think that might fix the imports, but it's not possible in the current setup as I require the other files in the src directory.
t
Yeah I figured but was curious if that fixed it
k
I have managed to fix the imports now. I tried
from services.x import service
as per the folder structure but as my module
x
contained a
-
it didn't work. When I recreated the problem with the
test
function I did not retest this style. eg.
users-api
would indicate an import of
services.users_api
which didn't work. removing the
-
allows the import to find it locally and in aws.
t
I'm not super familiar with python but the way our bundler works is we zip up everything that's in
src
. Is it possible that python needs a different import style for relative imports?
k
Thanks for the help @thdxr
f
Hey @Kyle Boucher, it might be SST not bundling the Python code correctly. Given ur project structure, should
require service
work? (ie. did it work in Serverless Framework)