
Vertex AI provides two types of notebooks: Google-managed and user-managed.
Google-managed notebooks automatically shut down after a period of inactivity, which helps save costs and prevent billing surprises. However, there isn’t an integrated method for automatically shutting down user-managed notebooks — until now.
Thanks to Jose Brache, you can now add similar functionality to user-managed notebooks in just a few simple steps.
Note that there is a difference in functionality between Google-managed notebooks and Jose’s solution. While managed notebooks shut down after a period of inactivity, Jose’s solution shuts them down after a specified amount of time, regardless of activity. Keep this distinction in mind.

Setup
The implementation consists of a Cloud Scheduler and a Cloud Function.
The Cloud Scheduler runs every 5 minutes calling the Cloud Function to check for notebooks that reached the shutdown time.
Per default, the Cloud Function checks Vertex AI Notebooks in the region us-central1 if needed, add more regions to the region list.
To set this up, follow the steps in the GitHub repository. Well-done and quick setup using Terraform.
Required Permissions / Roles
It’s worth mentioning that the Cloud Function’s service account needs the following permissions to stop the notebooks and list the projects.
roles/browseron the organization level to iterate over all projects in a specific organization. Not needed if you want to execute this in the same project as your Cloud Function is deployed.roles/notebooks.serviceAgentto list and stop the notebooks in the projects. If you want to shut down the notebook across projects, set this on…