How to use layers to use opencv for lambdas using Python 3.9/M1

Viewed 24

I'm trying to follow along with this tutorial (https://github.com/awslabs/lambda-opencv) but I keep getting errors with numpy when trying to test my AWS lambda function (x86 architecture). I pasted the error below:

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  * The Python version is: Python3.9 from "/var/lang/bin/python3.9"
  * The NumPy version is: "1.23.3"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: No module named 'numpy.core._multiarray_umath'

Does running the commands in the README with an M1 macbook impact things? I have also tried pip3 installing cv2 (4.6.0.66) and numpy (1.23.3) into a zipped package but this still produce the same errors (function is using arm architecture). I notice that when I have a function with x86 architecture I can get past the numpy error using an arn from Klayers (https://github.com/keithrozario/Klayers) but then I have an opencv error shown here:

Unable to import module 'lambda_function': /opt/python/lib/python3.9/site-packages/cv2/cv2.abi3.so: invalid ELF header

Does anyone know how to get the function in the tutorial working with layers? Any help is appreciated.

0 Answers
Related