Reputation: 2857
I'm trying to deploy a Google Cloud Platform function using a .zip file stored in the Google Storage.
My first try was using gcloud command:
gcloud functions deploy $FUNCTION_NAME --runtime=python37 --entry-point=endpoint --stage-bucket=my_bucket --memory=128MB --set-env-vars=var1=value1,var2=value2 --project=$GCP_PROJECT_ID --trigger-http
Then, I get the following error message:
....................................failed.
ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Function failed on loading user code. Error message: Cannot determine path without bucket name.
Also I tried to use the Google Cloud Platform web interface to deploy my function. I tried both Source code
options Zip upload
and Zip from cloud storage
, but still getting the same error.
PS.: when using the gcloud
command the files is zipped and uploaded successfully to the storage and the function created, but the function is with the error above.
Upvotes: 0
Views: 3590
Reputation: 2857
In my main.py
I have the following code:
(...)
STORAGE_BUCKET = os.environ.get('STORAGE_BUCKET')
storage_client = storage.Client()
bucket = storage_client.get_bucket(STORAGE_BUCKET)
(...)
But I forgot to set the STORAGE_BUCKET variable in the --set-env-vars=
.
So the error message it was regarding the storage_client.get_bucket(STORAGE_BUCKET)
and not to the deploy itself.
The error message should be more meaningful pointing to a error in the code.
Upvotes: 1
Reputation: 8056
I tried to reproduce your use case, and it worked as expected for me:
I followed the tutorial Quickstart: Using the gcloud Command-Line Tool
I zip the files: main.py
and requirements.txt
:
zip code.zip main.py requirements
I copied the zip file to my bucket:
gsutil cp code.zip gs://mybucket/
I deployed the cloud function:
gcloud functions deploy funczip --runtime=python37 --entry-point=hello_get --stage-bucket=mybucket --memory=128MB --set-env-vars=var1=World --project=myproject --trigger-http
I tested the function:
curl https://us-central1-myproject.cloudfunctions.net/funczip
Output:
Hello World!
Upvotes: 0