Problem running python script using TPU on VM instance - google-compute-engine

I created TPU and VM instance with same name via cloud console(not ctpu, gcloud).
When I check tpu on VM with command
gcloud compute tpus list
I get my TPU READY.
But when I run python script:
from tensorflow.contrib.cluster_resolver import TPUClusterResolver
tpu_grpc_url = TPUClusterResolver(tpu="v3-nonpre", zone="us-central1-a").get_master()
It says googleapiclient.errors.HttpError: <HttpError 403 when requesting https://tpu.googleapis.com/v1alpha1/projects/red-splice-230206/locations/us-central1-a/nodes/v3-nonpre?alt=json returned "Request had insufficient authentication scopes.">
What should I do more to get the required authentication?

Related

Changing an ApiGateway restapi stage deployment via the cli or sdk

I have a system in place for creating new deployments but I would like to be able to change a stage to use a previous deployment. You can do this via the aws console but it appears it's not an option for v1 API gateways via the SDK or CLI?
Can be done via CLI for V1 APIs. You will have to run two commands -> get-deployments and update-stage. Get the deployment ID from output of first and use it in the second.
$ aws apigateway get-deployments --rest-api-id $API_ID
$ aws apigateway update-stage --rest-api-id $API_ID --stage $STAGE_NAME --patch-operations op=replace,path=/deploymentId,value=$DEPLOYMENT_ID
get-deployments
update-stage

Cannot acces instance using compute ssh : "ERROR: [....putty.exe] exited with return code [1]

Here's my problem :
I would like to connect to a gcp instance. When I run the Google Cloud SDK shell as an administrator with the command :
gcloud compute ssh my_instance --zone=europe-west1-b -- -L=8081:locahost:8081
..I get this error : ERROR (gcloud.compute.ssh) [..../putty.exe] exited with return code [1]
My instance is running with the metadata enable-oslogin as TRUE, as the project.
Do you have an idea of what is the problem ?
When using -- in the command, you are passing SSH flags after the dashes and not gcloud command flags. To explain, gcloud compute ssh is a thin wrapper around the ssh(1) command that takes care of authentication and the translation of the instance name into an IP address.
In this case, -- is equivalent to --ssh-flag as per this SDK reference. It seems that putty is outputting an error that is not passed into the command line (SDK shell). The actual error should be visible in the dialog window before putty exits.
I have tried the command myself on Windows and the exact error was unknown option "L=8081:localhost:8081". The SSH flag is not accepted as you have an = sign there (typo).
According to linuxcommand.org manual, the flag should be in this format:
-L [bind_address:]port:host:hostport
Hence, you should run the command like this:
gcloud compute ssh my_instance --zone=europe-west1-b -- -L 8081:locahost:8081
Note also that you may have to create a firewall rule to allow Ingress to the instance on port 8081.

(gcloud.functions.deploy) permission denied when deploying function with specific service account

I'm trying to deploy Google Cloud Functions using a different service account. I have the service account properties saved to a json file. I swapped out the values to make it easier to read.
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/keys/mynewserviceaccount.json"
gcloud functions deploy MyFunction \
--runtime python37 \
--entry-point MyFunction \
--source src \
--service-account mynewserviceaccount#appspot.gserviceaccount.com \
--verbosity debug \
--stage-bucket staging.projectname.appspot.com \
--trigger-event providers/cloud.firestore/eventTypes/document.write \
--trigger-resource "projects/projectname/databases/(default)/documents/User/{userId}" &
mynewserviceaccount has the following roles. I've tried a few others and haven't had success.
- Cloud Functions Admin
- Cloud Functions Service Agent
- Errors Writer
- Service Account User
- Logs Writer
- Pub/Sub Subscriber
I've also ran
gcloud auth activate-service-account mynewserviceaccount#appspot.gserviceaccount.com --key-file "/path/to/keys/mynewserviceaccount.json"
When I run this, I get:
ERROR: (gcloud.functions.deploy) ResponseError: status=[403], code=[Forbidden], message=[The caller does not have permission]
When I try to find "gcloud.functions.deploy" in the Roles list, I don't see it. I don't know if this is an issue with documentation or an issue with the code.
The Docs on cloud functions states that if you want to deploy a function with a service account you have to do an extra step.
You must assign the user the IAM Service Account User role (roles/iam.serviceAccountUser) on the Cloud Functions Runtime service account.
if this was when running gcloud builds submit command, the most likely reason is Cloud Functions Developer role not being enabled for the Cloud Build service.
Navigate to Cloud Build > Settings
Enable Cloud Functions Developer Role

ERROR: Failed to configure trigger GCS Bucket

While issuing command gcloud beta functions deploy I get following error message in Terminal: ERROR: (gcloud.beta.functions.deploy) OperationError: code=13, message=Failed to configure trigger GCS Bucket: 18_bucket
Even tried to make simple function in Web UI (https://console.cloud.google.com/) I get same error (attach screenshot)
Trigger type: Cloud Storage bucket
Event Type: Finalize/Create
I believe i'm doing everything correct, even tried same steps in other Cloud Project, only in this Project (new project created few hours back) I get an error! Any idea what could be issues...
NOTE:
Already tried Disable & Re-enable Cloud Functions API
both GCS Bucket & Cloud Function is in same project
Thanks a lot for any clue into it..
UPDATE: ok, created fresh new project > Enabled Billing > Enabled Cloud Functions API > Created GCS Bucket > Create New Function (google.storage.object.finalize) > keeps giving same error: Deployment failure: Failed to configure trigger GCS Bucket: {{BUCKET NAME}}. HTTP Triggers works fine though
The problem has been solved by Google and was not related to our code :
https://status.firebase.google.com/incident/Functions/18024#5700609697120256

Getting 403 "Insufficient Permission" from gmail-api using get_application_default from a gce instance

I have the gmail api activated and I am on an instance with "full API access to all Google Cloud services". When I run the following from the instance:
credentials = GoogleCredentials.get_application_default()
service = build('gmail', 'v1', credentials=credentials)
service.users().messages().list(userId='me').execute()
I get:
HttpError: <HttpError 403 when requesting https://www.googleapis.com/gmail/v1/users/me/messages/send?alt=json returned "Insufficient Permission">
I have tried several other gmail-api calls and this is always the response.
You will need to use OAuth 2.0 for Server to Server Applications method.