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