Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

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, i.e.:

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}\"}"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading