V
V
Vladimir2019-11-29 15:54:48
Amazon Web Services
Vladimir, 2019-11-29 15:54:48

How to split flask app.py into modules in Zappa?

Hello!
There is app/__init__.py

from flask import Flask

app = Flask(__name__)


class HelloWorldService:

    def greeting(self):
        print('greeting app')
        return 'Hello World'


@app.route('/')
def index():
    hello = HelloWorldService()
    return hello.greeting(), 200


# include this for local dev
if __name__ == '__main__':
    app.run()

Lambda works successfully, everything is OK, but if I want to take out the routing in app/routes.py
from app import app

@app.route('/')
def index():
    hello = HelloWorldService()
    return hello.greeting(), 200

Or put HelloWorldService in app/services.py and in __init__ import from app.services import HelloWorldService
Then I get an error while executing 'zappa update':
Error: Warning! Status check on the deployed lambda failed. A GET request to '/' yielded a 502 response code.
Please tell me what is the problem? As I understand it, zappa loses its routing when importing.
Running 'flask run' locally does not suffer in all cases and everything is OK.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir, 2019-11-29
@FonVald

The repository for the example is https://github.com/tonyin/flask-zappa-base.
According to him, I was able to correctly set up the project structure so that flask with blueprints would work successfully with zappa.

I
Ivan Shumov, 2019-11-29
@inoise

Throw out Flask, throw out Zappa, take the Serverless Framework and refuse routing inside the lambda. Get used to AWS API Gateway

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question