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

使用gcloud部署Event Arc触发的二代Cloud Function如何指定Pub/Sub主题

解决方案

要解决这个错误,你需要在gcloud functions deploy命令中添加额外的--trigger-event-filters参数,指定Pub/Sub主题的完整资源路径。

修正后的完整命令如下:

gcloud functions deploy <function_name> \
--gen2 \
--source=. \
--trigger-event-filters=type=google.cloud.pubsub.topic.v1.messagePublished \
--trigger-event-filters=topic=projects/<project_id>/topics/<topic_name> \
--trigger-location=asia-southeast2 \
--trigger-service-account=<service_account> \
--runtime=python310 \
--entry-point=hello_pubsub \
--project=<project_id> \
--region=asia-southeast2

关键说明:

  • topic=projects/<project_id>/topics/<topic_name>:替换为你的Pub/Sub主题完整资源路径,其中<project_id>是GCP项目ID,<topic_name>是目标Pub/Sub主题的名称。
  • 确保--project参数值和主题路径中的<project_id>一致,避免跨项目权限问题。

该命令可直接用于Cloud Build流水线,只需提前配置好Cloud Build服务账号对Cloud Functions、Pub/Sub和Event Arc的相关权限。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.05 03:25:30