The Cloud ML instructions show how to grant Cloud ML access to a bucket using gsutil. Is there a way to do this programmatically in python?
Asked
Active
Viewed 117 times
1 Answers
2
You can use the google-cloud python libraries to programmatically give access to a GCS bucket to Cloud ML.
from google.cloud import storage
b = client.get_bucket(BUCKET)
# Grant WRITE access to the service account.
b.acl.user(SERVICE_ACCOUNT).grant_write()
b.acl.save()
# Change the default object permissions to give read access to the service account
b.default_object_acl.user(SERVICE_ACCOUNT).grant_read()
b.default_object_acl.save()
# Grant read access to all existing objects
for o in b.list_blobs():
o.acl.user(SERVICE_ACCOUNT).grant_read()
o.acl.save()
For instructions on obtaining the service account programmatically see this question

Community
- 1
- 1

Jeremy Lewi
- 6,386
- 6
- 22
- 37