繁体   English   中英

“错误:(gcloud.functions.call)ResponseError:状态= [404],代码= [确定],消息= [项目ABC中us-central1区域中的函数XYZ不存在]”

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

我正在测试云 function。

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

{"api_key":"MY_API_KEY"}

(将 MY_API_KEY 替换为纯文本密钥)然后 function 运行。

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

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而我的 function 是europe-west3 (来自“详细信息”选项卡)。

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

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]

注意上述命令不包括functions/region 我怀疑这是因为us-central1是默认 (.) 默认值。

gcloud config get-value functions/region
us-central1

我不鼓励将全局 state 存储在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}\"}"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM