Search code examples
pythonpandasnumpyaws-lambdaaws-lambda-layers

Not able to add pandas in aws layer and getting error


I'm getting error when I import pandas/numpy in lambda function:

I added pandas/numpy as a aws layer also I have added pymysql in same way, and it's working fine.

Working on windows 10,
Using python3.7 same in lambda also
Building zip package using pip install pandas -t
In dir - python\lib\python3.7\site-packages

{
  "errorMessage": "Unable to import module 'lambda_function': \n\nIMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!\n\nImporting the numpy C-extensions failed. This error can happen for\nmany reasons, often due to issues with your setup or how NumPy was\ninstalled.\n\nWe have compiled some common reasons and troubleshooting tips at:\n\n    https://numpy.org/devdocs/user/troubleshooting-importerror.html\n\nPlease note and check the following:\n\n  * The Python version is: Python3.7 from \"/var/lang/bin/python3.7\"\n  * The NumPy version is: \"1.19.1\"\n\nand make sure that they are the versions you expect.\nPlease carefully study the documentation linked above for further help.\n\nOriginal error was: No module named 'numpy.core._multiarray_umath'\n",
  "errorType": "Runtime.ImportModuleError"
}

Solution

  • zip of the package should be done in the build folder, even though you install the packages in the site-packages https://www.youtube.com/watch?v=zrrH9nbSPhQ - has some good steps to follow through.

    Pandas could be a huge zip file, that lambda layers might not support. You might want to check for pandas- example pandas-xlrd.