- 最新
- 投票最多
- 评论最多
The problem is how you’re installing and zipping the python libraries.
Every thing needs to be in a python folder as follows.
First, create a directory to hold everything. Replace my_layername with the name of your layer package
mkdir -p my-layername/python
Now install everything into the python directory
cd lambdalayer
cd python
pip3 install opencv-python-headless --target=.
Optional, but recommended -- remove unneeded files to reduce the size of your layer package. Note the last exit is only if you are running this inside a container:
rm -rf *.dist-info
find . -name "tests" -type d | xargs -I{} rm -rf {}
find . -name "docs" -type d | xargs -I{} rm -rf {}
find . -name "__pycache__" -type d | xargs -I{} rm -rf {}
rm -rf boto*
Now zip up the layer
cd my-layername
zip -r my-layername.zip python
Upload your layer to lambda.
Hello,
In order to import "opencv" module in your Lambda function as a layer you can refer to the below mentioned GitHub repository[+], it has the detailed steps mentioned on how to import cv2 in your Lambda function.
[+] https://github.com/awslabs/lambda-opencv
Additionally, you can create container based Lambda function and bake your on customer modules in the Dockerfile as it give you the ability to add modules/dependencies beyond 250MB.
[+] https://docs.aws.amazon.com/lambda/latest/dg/python-image.html
Thank you
相关内容
- AWS 官方已更新 1 年前
- AWS 官方已更新 1 年前
- AWS 官方已更新 5 个月前
- AWS 官方已更新 3 年前