How to deploy importing files in sub-directory

Hi.
I’m a serverless newbie.

We are making new service using serverless framework with python + aws.
We have project directory like below.

root — common / common.py
|-- regist / regist_handler.py
|-- upgrade / upgrade_handler.py

The file “common.py” is imported in regist_handler.py.

The file “regist_handler.py” includes below code to import file in sub-directory .
sys.path.insert(1, ‘…/common’)
from respond import respond

In this case, local test was finished successfully using pytest.
But after deploying on aws, test was failed due to “Unable import module…”.

I want to know how to deploy handler with sub-directory files.

You’re using 3 dots in your path. Isn’t that your issue?

1 Like

I solved it.

According this article, I must use PYTHONPATH instead of sys.