An open API service indexing awesome lists of open source software.

https://github.com/sloppycoder/gcp-vm-handler

cloud function to start/stop VM in GCP
https://github.com/sloppycoder/gcp-vm-handler

Last synced: over 1 year ago
JSON representation

cloud function to start/stop VM in GCP

Awesome Lists containing this project

README

          

## Cloud function to handle start/stop VM

Usage

```
# start VM associated to a token
curl http:///startvm?token=

# stop VM associated to a token
curl http:///stopvm?token=
```

### Local development

```

# get a service account credential json file from GCP
# place it in the current directory and name it service-account.json
# let API library know to use it as credential
# this step is not required when deployed into GCP

export GOOGLE_APPLICATION_CREDENTIALS=service-account.json

python3 -m venv
source venv/bin/activate
pip install -r requirements-dev.txt

# test using http trigger
functions-framework --target vm_action

# just run without functions framework
python main.py

```

### Deploy into GCP

```
gcloud functions deploy vm_action --runtime python37 --trigger-http

# create a scheduled job to send request to shutdown at 2am Singapore time

gcloud scheduler jobs create http stop-vm \
--schedule="05 02 * * *" \
--time-zone="Asia/Singapore" \
--http-method=get \
--uri=""

```