0

How can I use external python libraries in aws lambda function? I have tried to make a virtual environment using the following command:

py -m venv .lambda

Then I activate the venv using the following command:

.\.lambda\Scripts\activate

Then I install pyodbc in venv using the following command:

py -m pip install pyodbc

All of this goes well.

Now, when I want to use pyodbc in my aws lambda function I have zip the venv folder (.lambda) and upload it to a layer. I zip the folder by using "Compressed (zipped) folder".

I am uploading the zipped folder by going to layers in aws lambda function and press "create layers".

After creating the layer I use it in my aws lambda function. But even then when I try to import pyodbc library I get the error:

No module named 'pyodbc'

I am importing the library in my aws lambda function using the following command:

import pyodbc
15
  • Can it have something to do with the way i Call it? Commented Jul 27, 2021 at 8:40
  • Impossible to tell when you don't reveal how you do that; but generally speaking, yes it can. Please edit your question to replace the images with text, and include the command you are using to run the code etc. Commented Jul 27, 2021 at 8:41
  • I have added the commands. Is it clear or do you want more information? Commented Jul 27, 2021 at 8:54
  • I see no indication that you activate before you run the code which fails. Commented Jul 27, 2021 at 8:55
  • I activate the venv by using .\.lambda\Scripts\activate? Commented Jul 27, 2021 at 8:56

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.