You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

部署带Firestore文档创建触发器的Cloud Function遇400错误

解决Gen2 Cloud Function Firestore触发器部署错误

问题原因

你遇到的错误是因为Gen2 Cloud Function的Firestore create事件触发器不支持用document作为路径模式的属性,正确的路径匹配属性应该是resource,同时必须指定要监听的Firestore数据库。

修正后的部署命令

将原命令中的路径模式参数替换为针对resource属性的完整路径,并添加数据库过滤条件:

gcloud functions deploy send-verification-mail ^
  --gen2 ^
  --runtime=python312 ^
  --trigger-location=asia-south2 ^
  --region=asia-south2 ^
  --source=. ^
  --entry-point=send_verification_mail ^
  --set-env-vars GOOGLE_CLOUD_PROJECT=myproject ^
  --trigger-event-filters=type=google.cloud.firestore.document.v1.create ^
  --trigger-event-filters=database=(default) ^
  --trigger-event-filters-path-pattern=resource=projects/myproject/databases/(default)/documents/users/{username}

关键修正点

  • 替换document为resource:Gen2触发器要求路径匹配针对完整的资源路径,格式为projects/[项目ID]/databases/[数据库ID]/documents/[文档路径],默认数据库ID为(default)。
  • 添加数据库过滤:必须通过--trigger-event-filters=database=(default)指定要监听的Firestore数据库,否则触发器无法正确绑定到目标数据库。

内容的提问来源于stack exchange,提问作者Tanav Gupta

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 05:22:07