Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCP cloud functions with "gcloud functions deploy" fails with --source as file rather than directory

I'm trying to structure my GCP gcloud functions (in python) as a separate file per function. It sounds like from the documentation it should be supported but when I try to use --source as a file name instead of a directory it fails. Is there something I'm doing wrong?

Here is the command I use:

gcloud functions deploy createAccount --runtime python38 --trigger-http --source=postgres/createAccount.py --region us-central1

and the error I get back is:

ERROR: (gcloud.functions.deploy) argument --source: Provided path does not point to a directory

But if I put my "createAccount" python function in main.py inside the postgres directory and use this command the function deploys perfectly:

gcloud functions deploy createAccount --runtime python38 --trigger-http --source=postgres --region us-central1

Here it loojs as though it should accept file names in the --source option:

https://cloud.google.com/functions/docs/first-python

See this section:

enter image description here

Any ideas if there is a way to not make main.py one big monolith of all my cloud functions?

like image 305
Eradicatore Avatar asked Oct 17 '25 19:10

Eradicatore


1 Answers

If we look at the documentation of the gcloud command for deploying functions and the --source flag within:

https://cloud.google.com/sdk/gcloud/reference/functions/deploy#--source

We find that it unambiguously says that it wants a directory as a parameter and not a source file. The link you gave which seems to say that we can specify a file looks to be in error. I think that is a mistake and it can only be a directory that is supplied with --source.

This would seem to imply that you can create multiple directories ... where each directory contains just the function you wish to deploy.

like image 123
Kolban Avatar answered Oct 20 '25 09:10

Kolban