Python Flask 应用使用 google 云函数
Python flask app using google cloud functions
我了解 Google Cloud Functions 是 运行 函数的无服务器架构,我已经阅读了 Cloud Functions 的文档。我想 运行 一个完整的 Flask 应用程序,在 Cloud Functions 上使用 CRUD API。我看到了几篇关于 运行ning Python Functions on Cloud Functions 的文章。有人可以帮我找到 article/tutorial 关于如何通过单个 Cloud Function 运行 Flask 应用程序的方法吗?
如果你有flask应用,我推荐你使用Cloud Run。它与 Cloud Functions 非常相似(实际上它是相同的后端),但您可以 运行 一个容器。
我在 What I use and What I prefer between Cloud Functions and Cloud Run 上写了一篇文章。
如果您的 Flask 应用程序是标准的,您可以使用 standard Dockerfile to build it。更改 pip install
行(或添加另一行)以导入项目的依赖项
如果你的电脑上没有安装Docker,你可以像这样使用cloud build
gcloud builds submit -t gcr.io/<PROJECT_ID>/<CONTAINER_NAME>
然后,部署到云端运行
gcloud run deploy --image gcr.io/<PROJECT_ID>/<CONTAINER_NAME> --platform=managed
如果要求是 'single cloud function serving multiple routes' 而不一定是 'Flask/Python'(并且您很乐意编写 Javascript),那么具有 Express 服务器的云功能得到很好的支持:
https://firebase.google.com/docs/functions/http-events#using_existing_express_apps
(我怀疑这不是您要找的,但其他用户可能会觉得这有帮助)
我了解 Google Cloud Functions 是 运行 函数的无服务器架构,我已经阅读了 Cloud Functions 的文档。我想 运行 一个完整的 Flask 应用程序,在 Cloud Functions 上使用 CRUD API。我看到了几篇关于 运行ning Python Functions on Cloud Functions 的文章。有人可以帮我找到 article/tutorial 关于如何通过单个 Cloud Function 运行 Flask 应用程序的方法吗?
如果你有flask应用,我推荐你使用Cloud Run。它与 Cloud Functions 非常相似(实际上它是相同的后端),但您可以 运行 一个容器。
我在 What I use and What I prefer between Cloud Functions and Cloud Run 上写了一篇文章。
如果您的 Flask 应用程序是标准的,您可以使用 standard Dockerfile to build it。更改 pip install
行(或添加另一行)以导入项目的依赖项
如果你的电脑上没有安装Docker,你可以像这样使用cloud build
gcloud builds submit -t gcr.io/<PROJECT_ID>/<CONTAINER_NAME>
然后,部署到云端运行
gcloud run deploy --image gcr.io/<PROJECT_ID>/<CONTAINER_NAME> --platform=managed
如果要求是 'single cloud function serving multiple routes' 而不一定是 'Flask/Python'(并且您很乐意编写 Javascript),那么具有 Express 服务器的云功能得到很好的支持:
https://firebase.google.com/docs/functions/http-events#using_existing_express_apps
(我怀疑这不是您要找的,但其他用户可能会觉得这有帮助)