spacy 与 zappa 在 AWS lambda 上显示错误

spacy with zappa showing error on AWS lambda

我的 API 使用 Zappa 与 AWS lambda 完美配合。但是我的代码需要 spacy 到 运行。当我安装 spacy==2.0.13 并更新 zappa dev 时, api 停止工作。它给出了 502 错误。请帮助我解决这个问题。我已经将内存大小增加到3008

以下内容作为响应正文返回:

{'message': 'An uncaught exception happened while servicing this request. You can investigate this with the zappa tail command.', 'traceback': ['Traceback (most recent call last):\n', '  File \"/var/task/handler.py\", line 531, in handler\n    with Response.from_app(self.wsgi_app, environ) as response:\n', '  File \"/var/task/werkzeug/wrappers/base_response.py\", line 287, in from_app\n    return cls(*_run_wsgi_app(app, environ, buffered))\n', '  File \"/var/task/werkzeug/wrappers/base_response.py\", line 26, in _run_wsgi_app\n    return _run_wsgi_app(*args)\n', '  File \"/var/task/werkzeug/test.py\", line 1119, in run_wsgi_app\n    app_rv = app(environ, start_response)\n', \"TypeError: 'NoneType' object is not callable\n\"]}

来自 Zappa tail 的日志:

File "/var/task/handler.py", line 602, in lambda_handler
 return LambdaHandler.lambda_handler(event, context)
 File "/var/task/handler.py", line 245, in lambda_handler
 handler = cls()
 File "/var/task/handler.py", line 102, in __init__
 self.load_remote_project_archive(project_archive_path)
 File "/var/task/handler.py", line 174, in load_remote_project_archive
 t.extractall(project_folder)
 File "/var/lang/lib/python3.6/tarfile.py", line 2010, in extractall
 numeric_owner=numeric_owner)
 File "/var/lang/lib/python3.6/tarfile.py", line 2052, in extract
 numeric_owner=numeric_owner)
 File "/var/lang/lib/python3.6/tarfile.py", line 2122, in _extract_member
 self.makefile(tarinfo, targetpath)
 File "/var/lang/lib/python3.6/tarfile.py", line 2171, in makefile
 copyfileobj(source, target, tarinfo.size, ReadError, bufsize)
 File "/var/lang/lib/python3.6/tarfile.py", line 252, in copyfileobj
 dst.write(buf)

来自 Cloudwatch 控制台的日志:

[Errno 28] No space left on device: OSError
Traceback (most recent call last):
 File "/var/task/handler.py", line 602, in lambda_handler
   return LambdaHandler.lambda_handler(event, context)
 File "/var/task/handler.py", line 245, in lambda_handler
   handler = cls()
 File "/var/task/handler.py", line 102, in __init__
   self.load_remote_project_archive(project_archive_path)
 File "/var/task/handler.py", line 174, in load_remote_project_archive
   t.extractall(project_folder)
 File "/var/lang/lib/python3.6/tarfile.py", line 2010, in extractall
   numeric_owner=numeric_owner)
 File "/var/lang/lib/python3.6/tarfile.py", line 2052, in extract
   numeric_owner=numeric_owner)
 File "/var/lang/lib/python3.6/tarfile.py", line 2122, in _extract_member
   self.makefile(tarinfo, targetpath)
 File "/var/lang/lib/python3.6/tarfile.py", line 2171, in makefile
   copyfileobj(source, target, tarinfo.size, ReadError, bufsize)
 File "/var/lang/lib/python3.6/tarfile.py", line 252, in copyfileobj
   dst.write(buf)
OSError: [Errno 28] No space left on device

您的错误是 lambda 函数上没有 space。 SpaCy 需要相当多的 space。因此,请遵循以下建议: