-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_gcp.sh
47 lines (38 loc) · 1.59 KB
/
setup_gcp.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Start with a BLANK project
export PROJECT=$(gcloud info --format='value(config.project)')
export SERVICE_ACCOUNT_NAME="dataproc-service-account-3"
# Enable APIs
gcloud services enable \
dataproc.googleapis.com \
pubsub.googleapis.com \
cloudfunctions.googleapis.com \
datastore.googleapis.com
# Active Cloud DataStore by creating an App Engine app
gcloud app create --region=us-central
# Creates the tweet topic
gcloud pubsub topics create tweets
# Creates subscription
gcloud pubsub subscriptions create tweets-subscription --topic=tweets
# Create service accounts for Dataproc
gcloud iam service-accounts create $SERVICE_ACCOUNT_NAME
# Add Dataproc Worker IAM role
gcloud projects add-iam-policy-binding $PROJECT \
--role roles/dataproc.worker \
--member="serviceAccount:$SERVICE_ACCOUNT_NAME@$PROJECT.iam.gserviceaccount.com"
# Add Datastore user IAM role
gcloud projects add-iam-policy-binding $PROJECT \
--role roles/datastore.user \
--member="serviceAccount:$SERVICE_ACCOUNT_NAME@$PROJECT.iam.gserviceaccount.com"
# Add Cloud Pub/Sub subscriber IAM role
gcloud beta pubsub subscriptions add-iam-policy-binding \
tweets-subscription \
--role roles/pubsub.subscriber \
--member="serviceAccount:$SERVICE_ACCOUNT_NAME@$PROJECT.iam.gserviceaccount.com"
# Create Dataproc cluster
gcloud dataproc clusters create demo-cluster \
--zone=us-central1-a \
--scopes=pubsub,datastore \
--image-version=1.2 \
--worker-machine-type=n1-standard-2 \
--master-machine-type=n1-standard-2 \
--service-account="$SERVICE_ACCOUNT_NAME@$PROJECT.iam.gserviceaccount.com"