I need help setting up imports for a multi-Lambda project that utilizes AWS Lambda Layers. Here’s my current project structure:
/
├── pyproject.toml
└── lambdas/
├── function1/
│ ├── requirements.txt
│ ├── handler.py
│ └── __init__.py
├── function2/
│ ├── requirements.txt
│ ├── handler.py
│ └── __init__.py
└── layers/
└── shared/
└── python/
├── config/
├── constants/
└── utils/
In my function1/handler.py
file locally, I’m importing from a shared
layer. For instance, to import config
, I currently use:
import lambdas.layers.shared.python.config
However, when I deploy this to AWS Lambda, this import path isn’t available because I’m packaging only what’s inside function1/
for the Lambda, and shared/python
as a layer, following AWS Docs.
The root of the deployed Lambda looks like this with the layer:
requirements.txt
handler.py
__init__.py
I want to be able to import config
locally without errors, similar to how it would work in the deployed Lambda, like this:
import config
How can I achieve this setup? I’m using a single virtual environment for the entire project managed by Poetry.