使用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
相关产品推荐
相关产品推荐

