简体   繁体   中英

"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.

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:

{"api_key":"MY_API_KEY"}

(with MY_API_KEY to be replaced with a plain text key) then the function runs through.

From bash, using gcloud instead, the same function fails with:

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. 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).

How can I tell gcloud to use the region of the function, and not the default region? Or what would be another way to fix this?

gcloud assumes defaults (that may be get|set using 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"

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 ; I suspect this is because us-central1 is the default (.) default value.

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:

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}\"}"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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