Google Cloud Functions是一种轻量级,基于事件的异步计算解决方案,允许您创建以Node.js,Python或Go编写的小型单一用途函数,这些函数可响应云事件,而无需管理服务器或运行时环境。
借助Firebase HTTP功能,我们可以安装express并使用中间件。中间件对于在函数执行之前检查先决条件非常有用(除其他外)。例如,我们可以检查
来自 Google Cloud Functions 的 403 响应
尝试从 Web 执行 Cloud Function 端点时收到以下错误: 尝试从 Web 执行 Cloud Function 端点时收到以下错误: <!DOCTYPE html> <html lang=en> <meta charset=utf-8> <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width"> <title>Error 403 (Forbidden)!!1</title> <style> *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5pxno-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px} </style> <a href=//www.google.com/><span id=logo aria-label=Google></span></a> <p><b>403.</b> <ins>That’s an error.</ins> <p>Access is forbidden. <ins>That’s all we know.</ins> 我遵循了本教程:https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/functions/helloworld/main.py 调用此处所述的函数时:https://cloud.google.com/functions/docs/writing/http,我收到 403 错误。我已登录 gcloud 项目并使用正确的用户。 部署命令: gcloud beta functions deploy hello_get --runtime python37 --trigger-http 来自此文档:https://cloud.google.com/functions/docs/concepts/python-runtime 使用以下命令调用它: curl -X POST https://<REGION-PROJECT_ID>.cloudfunctions.net/hello_get 来自此文档:https://cloud.google.com/functions/docs/writing/http 这很奇怪,因为这件事大约三周前就开始发生了。旧函数停止工作并返回 403 响应。我在 UI 中部署了示例函数,它仅在从 UI 部署时有效,但在通过 http 请求访问端点时失败并显示 403。 此外,使用以下命令时,该函数成功执行:gcloud functions call hello_get 过去几周 GCF 身份验证有变化吗? 更新 我能够确定问题所在。我所在的项目和用户处于测试版身份验证程序中。切换到不在程序中的用户和项目后,我能够访问端点。 谢谢您的帮助。 在我看来,Google Cloud Functions 中添加了额外的 IAM 功能,因此,您可能没有打开所有用户对该功能的访问权限(仅供参考,这提供了对整个网络的访问权限)。 在 Cloud Functions 主页上,突出显示要添加所有访问权限的 Cloud Functions。 单击顶部栏上的“权限”。 单击“添加主体”并输入“allUsers”,然后在“角色”框中的“云函数”下选择“云函数调用者”。 点击“保存” 单击“允许公共访问” **针对云功能的新 Google UI 进行了更新 如果您在部署后使用第二代功能,则该过程与 @Mike Karp 的答案略有不同(似乎应该有效)。你需要: 转到 Google Cloud 控制台 单击您要授予访问权限的功能的链接名称。 单击功能详细信息概览页面右上角的 Powered By Cloud Run 链接。 打开“安全”选项卡,然后在“身份验证”下选择“允许未经身份验证的调用”。 单击“保存”。 来源:https://cloud.google.com/functions/docs/securing/managing-access-iam 通过 gcloud 部署时,添加 --allow-unauthenticated 标志,然后将具有调用者角色的成员 allUsers 添加到函数配置中。 样品 gcloud functions deploy my-function --gen2 --region=us-central1 --runtime=nodejs16 --entry-point=myFunction --trigger-http --allow-unauthenticated gcloud functions add-iam-policy-binding my-function --member="allUsers" --role="roles/cloudfunctions.invoker" --region=us-central1 仅供参考:https://cloud.google.com/functions/docs/securing/managing-access-iam#allowing_unauthenticated_http_function_inspiration 可以使用postman发送请求并获取JWT gcloud auth print-identity-token 基于 Mike 接受的答案和 上游错误报告 这是使用 Terraform 执行此操作的方法(给出 google_cloudfunctions2_function.function)。 resource "google_cloudfunctions2_function_iam_member" "public_invoker" { project = google_cloudfunctions2_function.function.project location = google_cloudfunctions2_function.function.location cloud_function = google_cloudfunctions2_function.function.name role = "roles/cloudfunctions.invoker" member = "allUsers" } resource "google_cloud_run_service_iam_member" "public_invoker" { location = google_cloudfunctions2_function.function.location service = google_cloudfunctions2_function.function.name role = "roles/run.invoker" member = "allUsers" } 我浏览了一些与相同错误相关的更多帖子。他们中的大多数人建议检查this链接以获得许可。还提到使用this文档使用稳定版本进行部署并重试。始终建议不要使用 beta,除非您需要任何 beta 标志来使用该命令。执行此操作之前,请确保您使用的是当前版本的 Google Cloud SDK。有一点尚不清楚,如果您用于在 UI 中部署相同的功能,那么该功能也应该使用端点来工作。
我有一个用 Swift 编写的 iOS 应用程序。我想将应用程序中的事件记录到 Google 的 Cloud Functions 记录器 SDK。我如何在 Swift 中管理它? 有一个来自 Google 的文档:https://firebase.goog...
Firebase HTTP Post 请求出现 404 Not Found 错误(“无法发布”)
已经被这个问题困扰好几天了:我正在尝试编写一个 firebase 云函数,该函数基于 HTTP post 触发器来更新 firestore 集合中的文档。我已经部署了火力基地
在 Firebase 函数上部署 Next.js 博客时出现 500 内部服务器错误
我目前正在部署一个使用 Next.js 构建的博客部分,作为我的 ReactJS 项目的一部分,旨在通过服务器端渲染 (SSR) 增强 SEO。为此,我使用 Firebase
如何导出名称包含连字符/破折号(短横线大小写)的 Firebase Cloud 函数 v2?
这是函数(与您从 firebase init 函数命令获得的 helloWorld 示例相同)。 从 'firebase-functions/v2/https' 导入 { onRequest } ; 导出 const helloWorld = onRequest((...
使用 Cloud Functions 时无法更改 Firebase 实时数据库中的数据
我想每天中午 12:00 重置 Firebase 实时数据库中的特定值。我正在使用 Firebase Cloud Functions 来执行此操作。这是我的代码: Exports.dailyReset = 函数....
如何在 GCP 中创建公有云功能(第 1 代),无需 auth 标头
在GCP云函数(第1代)中,如何使函数全局/公共,不需要任何auth标头。现在它总是需要一个不记名令牌。
我正在使用 firebase firestore 数据库和 firebase 函数。该文档是通过离子角度应用程序创建的,然后触发如下所示的 firebase 函数 导出.generateReadings =
如何从 AngularFire 调用 Firebase 函数
我使用functions.https.onRequest 创建了一个Firebase Cloud 函数,并使其像一个API 一样工作,使用Firebase 实时数据库中的JSON 数据进行响应。 然而,我发现了功能...
PostgreSQL 到 Google BigQuery 到云功能实时同步
我目前正在利用 Datastream 将数据的实时变化从 PostgreSQL 无缝复制到 BigQuery,并且该过程运行顺利。然而,我发现自己需要一个解决方案......
Firebase 功能无法使用 Admin SDK 连接到 Firestore
我正在使用 Admin SDK 编写一个 Firebase 函数,该函数应该从 Firestore 检索数据(函数在实时数据库插入事件时触发)。 看起来 Relatime DB 运行良好,但是
使用firebase函数调用firebase firestore时查询不是函数错误
我正在尝试使用 firebase 函数 gen2 从 firestore 中提取集合。我的代码如下所示 const {initializeApp } = require('firebase-admin/app'); const { getFirestore } = require('fi...
如何从 Firestore 获取所有文档并进行循环(云函数)
我正在尝试使用 Javascript 使用云函数访问我的 Firestore 数据库中的数据 我需要循环我拥有的所有文档(我有 7 个文档),但它只返回第一个文档并且
尝试将最后一个文档快照从 Firebase 云功能传递回客户端
我正在从 Firebase 云函数运行查询,我想返回最后一个快照,以便我可以使用它进行分页。我在记录器中获取了最后一个快照,但是出现以下错误:
尝试运行“firebase 部署”时,我在终端中收到错误。这会带来错误 1:7 错误 'functions' 被分配了一个值但从未使用过 no-unused-vars 这是我的 index.js 文件 //...
Github Actions 到 Google Functions 第二代
我正在使用 Github Action 来部署 Google Functions。如何使用第二代而不是第一代? 这是我的代码: .github/workflows/google-cloud-function.yaml # T...
我正在用python在gcp上构建一个云函数 我试图将此命令(在 bash 中)转换为 python : echo -e " [0;34m生成客户端配置json文件[0m" gcloud 我是...
无法上传 zip 文件:资源上的权限“iam.serviceAccounts.getAccessToken”被拒绝
我想通过GitHub Actions自动部署云函数 这是我的deploy-cloud-functions.yml 文件 名称:部署云函数 在: 推: 分支机构: - 壮举/队列 工作: 删除...
我在 google-firebase 上托管的 nextjs 项目(nextjs 网站)遇到了一些问题。我使用 google-cloud-functions 来运行这个网站。 我想使用缓存。据我了解网络应用程序...