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

如何从命令行调用Google Cloud Function?调用2代函数遇404错误

问题描述
  • 已创建Hello World版本的2代Google Cloud Function,通过curl调用可正常运行
  • 执行gcloud functions list确认函数存在:
NAME         STATE   TRIGGER       REGION       ENVIRONMENT
hello-world  ACTIVE  HTTP Trigger  us-central1  2nd gen
  • 执行gcloud functions call hello-world时返回404错误:
ERROR: (gcloud.functions.call) ResponseError: status=[404], code=[Ok], message=[Function hello-world in region us-central1 in project test-project does not exist]
  • 已尝试设置默认区域和可用区,但问题未解决:
gcloud compute project-info add-metadata \
   --metadata google-compute-default-region=us-central1,google-compute-default-zone=us-central1-a
解决方案

核心原因是gcloud functions call默认针对1代Cloud Function,不会自动识别2代环境,必须明确指定参数:

  1. 直接带参数调用2代函数:
gcloud functions call hello-world --gen2 --region=us-central1
  1. 若想永久默认调用2代函数,可设置gcloud配置:
gcloud config set functions/gen2 true

之后执行gcloud functions call hello-world --region=us-central1即可正常调用。

注:你之前输入的命令中出现了gcp前缀,正确的Google Cloud命令行工具前缀是gcloud,请修正后使用。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.19 13:45:45