OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How to import AWS Lambda Layers in a Multi-Lambda Python Project locally?

  • Thread starter Thread starter Adrian D.
  • Start date Start date
A

Adrian D.

Guest
I need help setting up imports for a multi-Lambda project that utilizes AWS Lambda Layers. Here's my current project structure:

Code:
/
├── 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:

Code:
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:

Code:
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:

Code:
import config

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

Latest posts

Top