Spanner
from google.cloud import spanner
import google.auth
from google.auth import impersonated_credentials
credentials ,project = google.auth.default() #get default credentials and project
target_credentials = impersonated_credentials.Credentials(source_credentials=credentials,
target_principals = impersonate_sa_to, #give sa to which you want to impersonate
target_scopes=["https://www.googleapis.com/auth/cloud-platform"]
)
spanner_client=spanner.Client(credentials=target_credentials)
instance = spanner_client.instance(instance_id)
database=instance.database(database_id)
Comments
Post a Comment