Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Call gcloud cmd to remove files in VM from Cloud Function

  • Currently, I've test and successful remove file in Cloud Shell.
  • What I want is to put this function by using subprocess. The systax is as below:
  • It shows me error:
    • 2022-08-29 17:44:20.371 ICTcall-py-test120u9l9echba compute: 1: compute: gcloud: not found
  • Some tried and still have the same error: 
    • Install gcloud on VM 
    • Add to requirement.txt:
      • google-api-core==1.26.3
        google-auth==1.28.1
        google-auth-oauthlib==0.4.4
        google-cloud-bigquery==2.13.1
        google-cloud-bigquery-storage==2.4.0
        google-cloud-core==1.6.0
        google-crc32c==1.1.2
        google-resumable-media==1.2.0

What I want is Calling a python file in VM from Cloud Function (After setting scheduler to turn on VM). What should I do to fix this error?

2 5 933
5 REPLIES 5

Is the code running in the VM terminal? I think your PATH was not set in bash_profile (or bashrc) during gcloud installation. Check if the path contains google-cloud-sdk in the command below

> echo $PATH

But Google Function shows the same error: "compute: gcloud: not found"
How to install Google Cloud SDK for Google Cloud Function? 

 

Does it work in VM (GCE)? But it doesn't work in cloud functions?

Have you tried installing gcloud in cloud functions? In general, it is difficult to expect gcloud to operate in a cloud function with a different level of abstraction than you think. (Can I install the sdk in cloud functions?)

If you have to make it work, try running cloud functions using container images (not sure). Install and include the gcloud sdk when creating the docker image. And put it on the Artifact Registry. Finally, run cloud functions with the image.

But... I think it would be better to look for a library instead of the sdk. good luck!

"Does it work in VM (GCE)? But it doesn't work in cloud functions?" => Yes, it works fine on VM, but Cloud Functions shows error. Thank you for your reply. 

I think my problem is quite a normal demand: "1. Use Cloud Functions & Scheduler to Turn on a VM, 2. then Call a Script on that VM and 3. Turn off the VM".  But at this moment, I've just Turn On and Turn Off VM. I still can't find the answer how to use Cloud Functions to Call a Script in VM. 

Hi i have quation