-
Buat service account
gcloud iam service-accounts create my-sa-123 --display-name "my service account"
-
Granting roles
gcloud projects add-iam-policy-binding $DEVSHELL_PROJECT_ID \ --member serviceAccount:my-sa-123@$DEVSHELL_PROJECT_ID.iam.gserviceaccount.com --role roles/editor
-
Buat service account
Navigation menu > IAM & Admin, Service accounts, + Create Service Account
-
Buat VM instances
-
Connect ssh
sudo apt-get update sudo apt-get install -y git python3-pip pip3 install --upgrade pip pip3 install google-cloud-bigquery pip3 install pyarrow pip3 install pandas pip3 install db-dtypes
-
Buat code python
echo " from google.auth import compute_engine from google.cloud import bigquery credentials = compute_engine.Credentials( service_account_email='YOUR_SERVICE_ACCOUNT') query = ''' SELECT year, COUNT(1) as num_babies FROM publicdata.samples.natality WHERE year > 2000 GROUP BY year ''' client = bigquery.Client( project='YOUR_PROJECT_ID', credentials=credentials) print(client.query(query).to_dataframe()) " > query.py
-
Replace project id
sed -i -e "s/YOUR_PROJECT_ID/$(gcloud config get-value project)/g" query.py
-
Replace service account
sed -i -e "s/YOUR_SERVICE_ACCOUNT/bigquery-qwiklab@$(gcloud config get-value project).iam.gserviceaccount.com/g" query.py
-
Run
python3 query.py