To use this cloud function follow these steps:
- Create a pub/sub topic which will be used to trigger the cloud function.
- Create the cloud function and copy in the code below.
- Make sure to set the correct project ID in line 8.
- Set the trigger to Pub/Sub and choose the topic created in step 1.
- Create a cloud scheduler job to trigger the cloud function on a regular basis.
- Choose the frequency when you want the cloud function to be triggered.
- Set the target to Pub/Sub and define the topic created in step 1.
- The payload should be set to
start [CloudSQL instance name]
orstop [CloudSQL instance name]
to start or stop the specified instance (e.g.start my_cloudsql_instance
will start the CloudSQL instance with the namemy_cloudsql_instance
)
Worked like a charm with runtime Python 3.9.