"ERROR: (gcloud.functions.call) ResponseError: status=[404], code=[Ok], message=[Function XYZ in region us-central1 in project ABC does not exist]"

"ERROR: (gcloud.functions.call) ResponseError: status=[404], code=[Ok], message=[Function XYZ in region us-central1 in project ABC does not exist]"

我正在测试云功能。

当我 运行 它来自“测试”选项卡时,在线,我将 json 字典作为参数粘贴到“触发”中作为云函数的请求变量传递事件”编辑为:

{"api_key":"MY_API_KEY"}

(用 MY_API_KEY 替换为纯文本密钥)然后函数 运行s 通过。

从 bash 开始,使用 gcloud 代替,相同的函数失败:

gcloud functions call MY_CLOUD_FUNCTION --data '{"api_key":"$API_KEY"}'
gcloud functions call MY_CLOUD_FUNCTION --data '{"api_key":"$API_KEY"}' 
ERROR: (gcloud.functions.call) ResponseError:
status=[404], code=[Ok], message=[Function MY_CLOUD_FUNCTION in region
us-central1 in project MY_CLOUD_PROJECT does not exist]

这很可能不是触发事件的问题,它恰好是 args 的一部分,但不应该在这里发挥作用。这是不同地区的问题。 gcloud 需要默认区域 us-central1,而我的函数是 europe-west3(来自“详细信息”选项卡)。

如何告诉 gcloud 使用函数的区域,而不是默认区域?或者还有什么方法可以解决这个问题?

gcloud 假定默认值(可以使用 gcloud config 获取|设置)

在这种情况下,您应该在命令中添加标志 --region=europe-west3 以指定目标区域,即:

REGION="europe-west3"

gcloud functions call your-function \
--region=${REGION} \
--data="{\"api_key\":\"${API_KEY}\"}"

您可以(希望如此)通过以下方式验证此行为:

gcloud config list
[core]
account = your@email.com

Your active configuration is: [default]

NOTE The above command does not include functions/region; I suspect this is because us-central1 is the default (!) default value.

gcloud config get-value functions/region
us-central1

我不鼓励在 gcloud config 中存储全局状态(部分原因是它会导致这种类型的混淆)但是,您也可以:

gcloud config set functions/region europe-west3
Updated property [functions/region].

gcloud config get-value functions/region
europe-west3

gcloud functions call your-function \
--data="{\"api_key\":\"${API_KEY}\"}"