START RequestId: 3d5691d9-ad79-4eed-a26c-5bc3f1a23a99 Version: $LATEST Unable to import module 'lambda_function': No module named 'pandas'
END RequestId: 3d5691d9-ad79-4eed-a26c-5bc3f1a23a99
I'm using Windows 7 64-bit as the host OS.
What I want to do
I simply want to use pandas in AWS-Lambda environment. Just like I use it in windows environment, I am looking for a simple solution for Lambda.
What I have tried so far
- Installed Xubuntu on a virtual box.
- Create a virtual environment called
myvenv
in Xubuntu on virtual-box. - Then I installed pandas3.6 in
myvenv
. - Thereafter, I copied the folder contents in
myvenv
at location'/usr/local/lib/python3.6/site-packages/'
to my host OS. - In the host OS (windows 7), I created a folder called
packs
, pasted the contents ofmyvenv
. - created a
lambda_function.py
script inpacks
in host OS (windows 7) - I then zipped the folder
packs
using 7zip software and upload it aszip
inLambda
- In Lambda, the lambda function handler name is,
lambda_handler()
. The code snippet looks like,
import pandas as pd
def lambda_handler(event, context): dates = pd.date_range('2019001', periods=6) df = pd.DataFrame(np.random.randn(6, 4), index=dates, columns=list('ABCD')) print(df)
- The handler is named as
lambda_function.lambda_handler
. I have given the lambda-roleAWSLambdaFullAccess
permission. - The time out is set to 4 min and 3 sec.
The test event looks like
{ "key1": "This will be printed if all OK" }
I have tried the following solutions:
- Tried precompiled linux-compatible binaries for pandas & numpy from here -- no luck.
- In Lambda, changed the
Handler info
to python_filename.function_name. For my case, it was lambda_function.lambda_handler -- failed with no module named 'pandas' error. - placed the lambda function in the root folder, zipped the folder using 7zip software and upload the folder to the S3 bucket. For my case, I placed the function at location
python\lib\python3.6\site_packages\lambda_function.py
failed with no module named 'pandas' error. - Already tried these related solutions posted on SO, 1, 2, 3, 4, 5, 6
Note: I do not want to use Docker, because I do not know how to use it and I'm not willing to learn it as I'm exasperated now. I'm coming from a windows environment (it sucks, I now know.)
Any ideas on how to get this to work.
psycopg2
). Though I don't do through some of the difficult steps you've described, what I usually do is just (1) Create a folder; (2) Add python files in created folder; (3) Install dependencies directly on that folder (i.e.pip install -t <folder_path_here> lib1 lib2); (4) Zip all the contents (
zip -r lambda.zip .`); (5) Upload zip file to lambda; – fixatdpandas
– fixatdpip install -t . pandas
and then zip the folder, upload it. – Lamanus