Tensorflow-Lambda-Layer
Tensorflow-Lambda-Layer copied to clipboard
Something wrong with module... maybe?
Followed the instructions but when I test a simple hello_world.py containing just "import keras" and a hello world lambda_handler, I get this error:
{
"errorMessage": "Unable to import module 'lambda_function': \n\nIMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!\n\nImporting the multiarray numpy extension module failed. Most\nlikely you are trying to import a failed build of numpy.\nHere is how to proceed:\n- If you're working with a numpy git repository, try git clean -xdf\n (removes all files not under version control) and rebuild numpy.\n- If you are simply trying to use the numpy version that you have installed:\n your installation is broken - please reinstall numpy.\n- If you have already reinstalled and that did not fix the problem, then:\n 1. Check that you are using the Python you expect (you're using /var/lang/bin/python3.7),\n and that you have no directories in your PATH or PYTHONPATH that can\n interfere with the Python and numpy versions you're trying to use.\n 2. If (1) looks fine, you can open a new issue at\n https://github.com/numpy/numpy/issues. Please include details on:\n - how you installed Python\n - how you installed numpy\n - your operating system\n - whether or not you have multiple versions of Python installed\n - if you built from source, your compiler versions and ideally a build log\n\n Note: this error has many possible causes, so please don't comment on\n an existing issue about this - open a new one instead.\n\nOriginal error was: No module named 'numpy.core._multiarray_umath'\n",
"errorType": "Runtime.ImportModuleError"
}
I don't think it is part of the layer. We had the same problem. We decided to side load numpy as there is no space in the package anymore.
Thanks for speaking up! Can you elaborate on the term "side load", and do you have instructions? I'm guessing you mean that you download the numpy package and install it outside the lambda_handler function, but I'm not sure, and it's not clear to me how you can install numpy from python itself. Thanks for any help!
I'm working on a blog on how to load the packages from S3 and the model as well. Will publish it in the coming days.
@douglasmason, check this one out: https://medium.com/wehkamp-techblog/aws-lambda-size-pil-tf-keras-numpy-f2b18de49f8c
@KeesCBakker your side load method is basically what serverless + serverless-python-requirements does; i.e. zip numpy along with the lambda function, then add run time unzip into /tmp
I also want to second that numpy is not part of the layer (or at least it doesn't seem to be accessible)
OP's error can be caused by trying to use Python 3.8 in AWS Lambda. Choose 3.6 as the runtime instead.