【发布时间】:2020-02-16 10:36:22
【问题描述】:
我正在尝试使用Zappa 项目将使用flask_restplus 和flask_injector 包的python 项目部署到AWS Lambda,但它不起作用,当我尝试调用API 网关时它会引发错误Zappa 为项目自动创建:
[错误] AttributeError:类型对象“可调用”没有属性“_abc_registry” 回溯(最近一次通话最后一次):
文件“/var/task/handler.py”,第 602 行,在 lambda_handler 返回 LambdaHandler.lambda_handler(事件,上下文)
文件“/var/task/handler.py”,第 245 行,在 lambda_handler 处理程序 = cls()
init 中的文件“/var/task/handler.py”,第 139 行 self.app_module = importlib.import_module(self.settings.APP_MODULE) 文件“/var/lang/lib/python3.7/importlib/init.py”,第 127 行,在 import_module return _bootstrap._gcd_import(name[level:], package, level)
文件“”,第 1006 行,在 _gcd_import
文件“”,第 983 行,在 _find_and_load
文件“”,第 967 行,在 _find_and_load_unlocked
文件“”,第 677 行,在 _load_unlocked
文件“”,第 728 行,在 exec_module
文件“”,第 219 行,在 _call_with_frames_removed
文件“/var/task/app.py”,第 1 行,在 从启动导入启动
文件“/var/task/startup.py”,第 3 行,在 从 flask_injector 导入 FlaskInjector
文件“/var/task/flask_injector.py”,第 13 行,在 从输入 import Any、Callable、cast、Dict、get_type_hints、Iterable、List、TypeVar、Union
文件“/var/task/typing.py”,第 1357 行,在 类 Callable(extra=collections_abc.Callable, metaclass=CallableMeta):
新建中的文件“/var/task/typing.py”,第 1005 行 self._abc_registry = extra._abc_registry
该项目仅包含两个 Python 文件:
- app.py:
from startup import Startup
app = Startup.start_app()
- startup.py:
from flask import Flask
from flask_restplus import Api
# if I removed the following line, the project works perfectly.
from flask_injector import FlaskInjector
class Startup():
@staticmethod
def start_app():
appObj = Flask(__name__)
appObj.secret_key = '123123'
app = appObj
print("It's working")
return app
还有zappa_settings.json 文件
{
"dev": {
"app_function": "app.app",
"aws_region": "[My Region]",
"profile_name": "default",
"project_name": "my-api-test",
"runtime": "python3.7",
"s3_bucket": "[An S3 bucket name]",
"keep_warm": false,
"memory_size": 1024,
"timeout_seconds": 90,
"manage_roles": false,
"role_name": "[A specific role name to deploy the project]",
"role_arn": "[Role ARN]"
}
}
我不知道这里有什么问题,为什么使用flask_injector 会导致这个错误?
【问题讨论】:
标签: python aws-lambda zappa flask-injector