Kleyson Rios
Kleyson Rios

Reputation: 2857

Google Cloud Plataform functions with error message: Cannot determine path without bucket name

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.

enter image description here

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

Answers (2)

Kleyson Rios
Kleyson Rios

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

marian.vladoi
marian.vladoi

Reputation: 8056

I tried to reproduce your use case, and it worked as expected for me:

  1. I followed the tutorial Quickstart: Using the gcloud Command-Line Tool

  2. I zip the files: main.py and requirements.txt:

    zip code.zip main.py requirements
    
  3. I copied the zip file to my bucket:

    gsutil cp code.zip gs://mybucket/ 
    
  4. 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
    
  5. I tested the function:

    curl  https://us-central1-myproject.cloudfunctions.net/funczip
    
  6. Output:

    Hello World!
    

Upvotes: 0

Related Questions