我试图使用python3.7运行时的Serverless框架部署一个AWS Lambda函数,我需要将dlib打包为依赖项并在lambda函数中导入。有什么想法吗?让dlib在python3.7上工作并成功地使用Serverless框架的最简单方法是什么?蒂娅..。
更新:我已经将添加到中,我使用的是Serverless插件无服务器- python -requirements,我使用bitbucket管道进行部署,使用的是带有python和节点库的ubuntu映像。我还在管道脚本中安装了cmake,因为正如我所见,dlib需要它来编译。
管道失败的原因如下:
Container 'Build' exceeded memory limit.dlib编译以77%的速度停止,并发出以下反复出现的弃用警告,直到管道超过内存并因失败而停止:
Scanning dependencies of target dlib
.
.
[ 77%] Building CXX object CMakeFiles/dlib_python.dir/src/other.cpp.o
In file included from /tmp/pip-install-nx1hok9_/dlib/dlib/external/pybind11/include/pybind11/cast.h:16,
from /tmp/pip-install-nx1hok9_/dlib/dlib/external/pybind11/include/pybind11/attr.h:13,
from /tmp/pip-install-nx1hok9_/dlib/dlib/external/pybind11/include/pybind11/pybind11.h:43,
from /tmp/pip-install-nx1hok9_/dlib/dlib/../dlib/python/pybind_utils.h:6,
from /tmp/pip-install-nx1hok9_/dlib/dlib/../dlib/python.h:6,
from /tmp/pip-install-nx1hok9_/dlib/tools/python/src/basic.cpp:3:
/tmp/pip-install-nx1hok9_/dlib/dlib/external/pybind11/include/pybind11/detail/internals.h:82:34: warning: ‘int PyThread_create_key()’ is deprecated [-Wdeprecated-declarations]
decltype(PyThread_create_key()) tstate = 0; // Usually an int but a long on Cygwin64 with Python 3.x
^
In file included from /usr/local/include/python3.7m/pystate.h:11,
from /usr/local/include/python3.7m/traceback.h:8,
from /usr/local/include/python3.7m/Python.h:119,
from /tmp/pip-install-nx1hok9_/dlib/dlib/external/pybind11/include/pybind11/detail/common.h:111,
from /tmp/pip-install-nx1hok9_/dlib/dlib/external/pybind11/include/pybind11/pytypes.h:12,
from /tmp/pip-install-nx1hok9_/dlib/dlib/external/pybind11/include/pybind11/cast.h:13,
from /tmp/pip-install-nx1hok9_/dlib/dlib/external/pybind11/include/pybind11/attr.h:13,
from /tmp/pip-install-nx1hok9_/dlib/dlib/external/pybind11/include/pybind11/pybind11.h:43,
from /tmp/pip-install-nx1hok9_/dlib/dlib/../dlib/python/pybind_utils.h:6,
from /tmp/pip-install-nx1hok9_/dlib/dlib/../dlib/python.h:6,
from /tmp/pip-install-nx1hok9_/dlib/tools/python/src/basic.cpp:3:
/usr/local/include/python3.7m/pythread.h:95:17: note: declared here
PyAPI_FUNC(int) PyThread_create_key(void) Py_DEPRECATED(3.7);
^~~~~~~~~~~~~~~~~~~
In file included from /tmp/pip-install-nx1hok9_/dlib/dlib/external/pybind11/include/pybind11/cast.h:16,
from /tmp/pip-install-nx1hok9_/dlib/dlib/external/pybind11/include/pybind11/attr.h:13,
from /tmp/pip-install-nx1hok9_/dlib/dlib/external/pybind11/include/pybind11/pybind11.h:43,
from /tmp/pip-install-nx1hok9_/dlib/dlib/../dlib/python/pybind_utils.h:6,
from /tmp/pip-install-nx1hok9_/dlib/dlib/../dlib/python.h:6,
from /tmp/pip-install-nx1hok9_/dlib/tools/python/src/basic.cpp:3:
/tmp/pip-install-nx1hok9_/dlib/dlib/external/pybind11/include/pybind11/detail/internals.h:82:34: warning: ‘int PyThread_create_key()’ is deprecated [-Wdeprecated-declarations]
decltype(PyThread_create_key()) tstate = 0; // Usually an int but a long on Cygwin64 with Python 3.x
^
In file included from /usr/local/include/python3.7m/pystate.h:11,
在这里输入代码
发布于 2020-05-08 20:16:48
好的,我通过将管道大小增加到2倍来解决这个问题,它成功了。
发布于 2020-05-07 04:57:54
马辛的建议行得通,但有些乏味。幸运的是,这里出现了无服务器的框架来拯救。下面的示例使用Python3.8,但可以轻松地将其切换到3.7。
前提条件:
npm install --save serverless-python-requirementsserverless.yml
service: dlib-example
provider:
name: aws
runtime: python3.8
functions:
dlib:
handler: handler.main
layers:
- {Ref: PythonRequirementsLambdaLayer}
plugins:
- serverless-python-requirements
custom:
pythonRequirements:
dockerizePip: non-linux
layer: truerequirements.txt
dlib==19.19.0handler.py
import dlib
def main(event, context):
print(dlib.__version__)
if __name__ == "__main__":
main('', '')然后使用sls deploy构建依赖关系(在停靠容器中),并使用CloudFormation部署到AWS。
测试
运行sls invoke -f dlib --log,您将得到如下内容:
null
--------------------------------------------------------------------
START RequestId: 9fba7253-2f3b-425f-a0b7-9ee3dfaec13b Version: $LATEST
19.19.0
END RequestId: 9fba7253-2f3b-425f-a0b7-9ee3dfaec13b
REPORT RequestId: 9fba7253-2f3b-425f-a0b7-9ee3dfaec13b Duration: 1.66 ms Billed Duration: 100 ms Memory Size: 1024 MB Max Memory Used: 62 MB Init Duration: 227.31 ms干杯!
https://stackoverflow.com/questions/61648983
复制相似问题