IAM Roles

In Google Kubernetes Engine Set Up we have explained how to install google-cloud-sdk and configure a project. Here we explain how to use google storage.

First let’s create a role. For example:

gcloud iam service-accounts create <user_name>

Then

gcloud projects add-iam-policy-binding <project_name>\
    --member "serviceAccount:<user_name>@<project_name>.iam.gserviceaccount.com"\
    --role "roles/owner"

Then

mkdir ~/.gcloud
gcloud iam service-accounts keys create ~/.gcloud/<user_name>_<project_name>.json\
    --iam-account <user_name>@<project_name>.iam.gserviceaccount.com

and add to .zshrc:

export GOOGLE_APPLICATION_CREDENTIALS="~/.gcloud/<user_name>_<project_name>.json"

Install Google Cloud Storage Client Library

pip install google-cloud-storage

Operation with gsutil

List buckets

gsutil ls

Creating bucket

gsutil mb gs://bartek-test-bucket/

Deleting buckets

gsutil rm -r gs://bartek-test-bucket/

Uploading buckets

gsutil cp <file_name> gs://<bucket_name>/<destination>

Listing objects

gsutil ls -r gs://<bucket_name>/path

Deleting objects

gsutil rm gs://<bucket_name>/<object_name>

Operation with python

See python notebook:

https://github.com/bartek-blog/bartek-blog.github.io/blob/master/jupyter/2019-12-29-gstorage.ipynb

Updated: 2019-12-30