0
votes

I'm trying to deploy a python project uses flask_restplus and flask_injector packages to AWS Lambda using Zappa project, but it doesn't work, it throws an error when I try to call the API gateway that Zappa automatically created for the project:

[ERROR] AttributeError: type object 'Callable' has no attribute '_abc_registry' 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 139, in init self.app_module = importlib.import_module(self.settings.APP_MODULE) File "/var/lang/lib/python3.7/importlib/init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1006, in _gcd_import
File "", line 983, in _find_and_load
File "", line 967, in _find_and_load_unlocked
File "", line 677, in _load_unlocked
File "", line 728, in exec_module
File "", line 219, in _call_with_frames_removed
File "/var/task/app.py", line 1, in from startup import Startup
File "/var/task/startup.py", line 3, in from flask_injector import FlaskInjector
File "/var/task/flask_injector.py", line 13, in from typing import Any, Callable, cast, Dict, get_type_hints, Iterable, List, TypeVar, Union
File "/var/task/typing.py", line 1357, in class Callable(extra=collections_abc.Callable, metaclass=CallableMeta):
File "/var/task/typing.py", line 1005, in new self._abc_registry = extra._abc_registry

The project consists of two Python files only:

  • 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

And the zappa_settings.json file

{
    "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]"
    }
}

I don't know what's the issue here, why using flask_injector causes this error?

1

1 Answers

1
votes

After more investigation on the issue, and reading an answer from Amazon:
https://forums.developer.amazon.com/questions/191460/ask-sdk-for-python-14-possible-issue-when-deployed.html

I figured out that one of my dependencies installs the package typing (which can be found as standard python package), and by removing it the problem solved.

So just do:

pip uninstall typing

and you should be good to go.