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
- Host: GitHub
- URL: https://github.com/sloppycoder/gcp-vm-handler
- Owner: sloppycoder
- Created: 2020-01-17T12:54:16.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-01-19T16:28:28.000Z (over 6 years ago)
- Last Synced: 2025-01-11T08:14:02.502Z (over 1 year ago)
- Language: Python
- Size: 2.93 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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=""
```