Abstract
To use openCV on AWS Lambda, I complied a zip file with the openCV package and a python program and save it in AWS S3. After that, I execute it by indicating the URL of the program on S3. However, I got the error below.
Error Message
Error
[ERROR] Runtime.ImportModuleError: Unable to import module 'lambda_function': No module named 'cv2.cv2'
whole log
START RequestId: 58869885-9abd-4b18-8393-6d023d268637 Version: $LATEST
[ERROR] Runtime.ImportModuleError: Unable to import module 'lambda_function': No module named 'cv2.cv2'
END RequestId: 58869885-9abd-4b18-8393-6d023d268637
REPORT RequestId: 58869885-9abd-4b18-8393-6d023d268637 Duration: 1.59 ms Billed Duration: 2 ms Memory Size: 256 MB Max Memory Used: 66 MB Init Duration: 294.98 ms
※ There is a python file called lambda_function.py in the zip file saved in S3. import cv2
is executed in the python file.
What I tried
I thought there is a trouble in the version of opencv or compatibility with other packages. I changed two points below, but it didn't work.
- from
import opencv-python -t .
topip install opencv-python==3.4.5.20 -t .
- I created a virtual environment with
python3 venv (vertual env name)
, and executed pip install command.
※ I can import cv2
and execute lambda_function.py
in my computer.
zip file contents in S3
lambda-package.zip
- lambda_function.py
- bin
- cv2
- include
- lib
- numpy
- numpy-1.20.1.dist-info
- opencv_python-3.4.5.20.dist-info
- pyvenv.cfg
my environment
- venv Python:3.7.6
- Lambda Python:3.7
- OpenCV:3.4.5.20
- Lambda Timeout:1min
- Lambda Memory:256MB
Thank you for your kindness.