I'm starting to learn Google App Engine, and have written a basic main.py file with a Flask application, which works fine. Here's the first few lines of code:
from flask import Flask, jsonify
app = Flask(__name__)
@app.route("/")
def root():
return jsonify({'status': "Success!"}), 200
I wanted to change the name of the script, so I renamed it 'test-app.py' and added this line to app.yaml:
runtime: python38
entrypoint: test-app:app
Then re-run gcloud app deploy. The deployment is successful, but app returns 500 with this in the logs:
2021-05-09 22:23:40 default[20210509t222122] "GET / HTTP/1.1" 500
2021-05-09 22:23:41 default[20210509t222122] /bin/sh: 1: exec: test-app:app: not found
I also tried these from the documentation:
entrypoint: gunicorn -b :$PORT test-app:app
entrypoint: uwsgi --http :$PORT --wsgi-file test-app.py --callable application
In both cases, logs show "/bin/sh: 1: exec: (gunicorn|uwsgi): not found"
In Lambda, the Entry point is set via the handler option, which is by default a function called lambda_handler() in a file called lambda_function. It would appear App Engine uses "app" inside "main.py", but what's the proper syntax for changing this?
Your app is not working most probably because you forgot to add gunicorn to your dependencies.
In your requirements.txt file add the following line (you can change the version):
gunicorn==19.3.0
Then in app.yaml add the following line:
entrypoint: gunicorn -b :$PORT test_app:app
This should be enough for the default app to run as expected.
However if you want more complicated configuration for your server you can create a guniconrn.conf.py and add the your preference to it. In that case you have to specify it in your entry point:
entrypoint: gunicorn -c gunicorn.conf.py -b :$PORT main:app
This answer above is mostly correct, but doesn't explain the root cause. The documentation says gunicorn is the "recommended" web server, but in reality it's the default web server when web-based apps are deployed.
When deploying a Flask app on App Engine, gunicorn becomes a hidden dependency and assumes the entry point to app() in main.py. For a custom file/entry point, it does need of course to be set in the YAML file like so:
entrypoint: gunicorn -w 2 test_app:app
Or, if using uwsgi as the web server rather than gunicorn:
entrypoint: uwsgi --http :$PORT --wsgi-file test_app.py --callable app --enable-threads
In either case, uwsgi or gunicorn are no longer hidden dependencies, and thus need to be specified in the requirements.txt file. Personally, I was not familiar with either, since I'd used Werkzeug or Apache/mod_wsgi
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With