Search code examples
pythonflaskgoogle-cloud-platformgoogle-cloud-functionsflask-restful

Python flask app using google cloud functions


I understand that Google Cloud Functions is a serverless architecture to run functions and I have gone through the documentation of Cloud Functions. I want to run an entire Flask app with CRUD APIs on Cloud Functions. I saw several articles on running Python Functions on Cloud Functions. Can someone help me find an article/tutorial on how to run a Flask app through a single Cloud Function?


Solution

  • If you have a flask application, I recommend you to use Cloud Run. It's very similar to Cloud Functions (in reality it's the same backend) but you can run a container.

    I have wrote an article on What I use and What I prefer between Cloud Functions and Cloud Run.

    If your flask app is standard, you can use a standard Dockerfile to build it. Change the pip install line (or add another one) to import the dependencies of your project

    If you haven't Docker installed on your computer, you can use cloud build like this

    gcloud builds submit -t gcr.io/<PROJECT_ID>/<CONTAINER_NAME>
    

    And then, deploy on Cloud Run

    gcloud run deploy --image gcr.io/<PROJECT_ID>/<CONTAINER_NAME> --platform=managed