Member-only story
Deploy your Flask app on the Google Cloud Platform
From localhost to the world wide web with GCP
Assuming you have successfully converted your Python project into a Flask app under localhost.
if __name__ == "__main__":
app.run()
In five simple steps, we will deploy this app (main.py in this example) to the Google Cloud Platform. This will make your Flask app accessible from anywhere in the world over the Internet.
Solution
One approach to deploying the Flask (localhost) app on the Google Cloud Platform (GCP) is to use Google App Engine (GAE).
- Create a GCP project: If you don’t already have a GCP account, create one and create a new project.
- Set up the Cloud SDK: Install the Cloud SDK on your local machine if you haven’t already.
- Set up the app.yaml file: Create an app.yaml file in the root directory of your project. This file is used to configure your GAE environment. Here’s an example:
runtime: python39
entrypoint: gunicorn -b :$PORT main:app
handlers:
- url: /.*
script: auto
This example specifies the Python 3.9 runtime and uses Gunicorn as the server. The entrypoint
line specifies the command to start the server. The handlers
section…