forked from https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git
reference document: https://cloud.google.com/scheduler/docs/start-and-stop-compute-engine-instances-on-a-schedule
gcloud pubsub topics create stop-instance-event
gcloud pubsub topics list
Do NOT use Node.js 8 run time
git clone https://github.com/goto-satoru/cloud-functions-sample-nodejs10.git
cd cloud-functions-sample-nodejs10/stop-instance
gcloud functions deploy stopInstancePubSub --trigger-topic stop-instance-event --runtime nodejs10 --region=asia-northeast1
gcloud functions list
stop all GCE instances in asia-northeast1-a, asia-northeast1-b and asia-northeast1-c regions which have env=test label.
gcloud beta scheduler jobs create pubsub stop-instances-a --schedule '0 23 * * *' --topic stop-instance-event --message-body '{"zone":"asia-northeast1-a", "label":"env=test"}' --time-zone 'Asia/Tokyo'
gcloud beta scheduler jobs create pubsub stop-instances-b --schedule '0 23 * * *' --topic stop-instance-event --message-body '{"zone":"asia-northeast1-b", "label":"env=test"}' --time-zone 'Asia/Tokyo'
gcloud beta scheduler jobs create pubsub stop-instances-c --schedule '0 23 * * *' --topic stop-instance-event --message-body '{"zone":"asia-northeast1-c", "label":"env=test"}' --time-zone 'Asia/Tokyo'
gcloud beta scheduler jobs list