[英]"ERROR: (gcloud.functions.call) ResponseError: status=[404], code=[Ok], message=[Function XYZ in region us-central1 in project ABC does not exist]"
I am testing a cloud function.我正在测试云 function。
When I run it from the "Testing" tab, online, and I paste the json dictionary as the argument to be passed as the request variable of the cloud function in the "Triggering event" editor as:当我从“测试”选项卡在线运行它时,我将 json 字典作为参数粘贴到“触发事件”编辑器中作为云 function 的请求变量传递为:
{"api_key":"MY_API_KEY"}
(with MY_API_KEY to be replaced with a plain text key) then the function runs through. (将 MY_API_KEY 替换为纯文本密钥)然后 function 运行。
From bash, using gcloud
instead, the same function fails with:从 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]
And this is most likely not a problem of the triggering event which just happens to be part of the args but should not play a role here.这很可能不是触发事件的问题,它恰好是 args 的一部分,但不应该在这里发挥作用。 It is a problem of the different regions.
这是不同地区的问题。
gcloud
expects the default region us-central1
while my function is europe-west3
(from the "Details" tab). gcloud
需要默认区域us-central1
而我的 function 是europe-west3
(来自“详细信息”选项卡)。
How can I tell gcloud
to use the region of the function, and not the default region?如何告诉
gcloud
使用 function 的区域,而不是默认区域? Or what would be another way to fix this?或者还有什么方法可以解决这个问题?
gcloud
assumes defaults (that may be get|set using gcloud config
) gcloud
假定默认值(可以使用gcloud config
获取|设置)
In this case, you should add the flag --region=europe-west3
to your command to specify the intended region, ie:在这种情况下,您应该在命令中添加标志
--region=europe-west3
以指定预期区域,即:
REGION="europe-west3"
gcloud functions call your-function \
--region=${REGION} \
--data="{\"api_key\":\"${API_KEY}\"}"
You can verify this behavior (hopefully) by:您可以通过以下方式验证此行为(希望如此):
gcloud config list
[core]
account = your@email.com
Your active configuration is: [default]
NOTE The above command does not include
functions/region
;注意上述命令不包括
functions/region
; I suspect this is becauseus-central1
is the default (.) default value.我怀疑这是因为
us-central1
是默认 (.) 默认值。
gcloud config get-value functions/region
us-central1
I discourage storing global state in gcloud config
(partly because it results in this type of confusion) but, you may also:我不鼓励将全局 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.