In this blog, we’ll discuss how to Schedule Virtual Machines (start & stop) and how failure to auto-schedule VMs results in increased costs.
Schedule Virtual Machines on Google Cloud


When migrating your workload to the cloud, the related costs are the first thing put up for discussion. Cost is one of the driving factors, that leads organizations to opt for the cloud in the first place. Considering the current unpredictable circumstances, cloud services are the ideal solution. Although investing in cloud services is the best way to go, the costs can quickly spiral out of control if they are not kept in check. According to a HashiCorp- Forester 2022 Cloud Report, 94% of enterprises are overspending in the cloud. The combination of factors resulting in this scenario for businesses includes: idle or underused resources e.g. (VMs), over-provisioning of cloud resources, poor cloud architecture, failing to utilize cloud commitments, and going against best practices during the use of various services.

The good news is that, with some basic analysis and proper planning, you can regain control of your Google Cloud costs and achieve true cost optimization. There are several ways to minimize compute costs without changing your cloud architecture. These include.

  • using committed-use discounts
  • leveraging preemptible VMs
  • scheduling VMs to auto -start and stop
  • VM right-sizing, and
  • utilizing idle VM recommendations.

In this blog, we’ll discuss the scheduling of VMs to start and stop, how failure to auto-schedule VMs results in increased costs and how we have implemented this mechanism to help businesses like yours keep their cloud costs under control.

Google Cloud Vitual Machines (VMs): How they accrue costs.

Pay-as-you-go cloud computing is a popular cloud computing payment method, that charges for service use. You only pay when you use the service. Remember that charges will be incurred as long as your Virtual Machine (VM ) is running, regardless of whether you are actually doing anything with it.

It sounds excellent except for one catch; you may forget to shut down the instances that are not being used at certain times, which ends up costing lots. How many hours are your servers running per month?

If your Google Cloud servers are only busy during regular business hours, or only during certain times of the week or month, you can save money by identifying the block of the time these VMs typically use and then keep them in a stopped state during the off- hours. Can this be scheduled in the Google Cloud console? And if not – what’s the alternative?

We find that some organizations’ cloud resources are for non-production purposes. These resources are only needed when employees are actively using them during working hours. So, every second they are left running when not in use, is a wasted spend. Those VM instances often have predictable workloads, such as an 8 AM to 5 PM work week, 5 days a week. For instance, we could consider shutting down the server after the close of business and have them start up before people arrive in the office the next day. This will be billed for only 9 hours instead of 24. This will in turn result in significant cost savings.

Google cloud has instance schedulers that let you start and stop the VMs automatically, to optimize on costs and manage VM instances more efficiently using policies detailing the start and stop behaviour. Google’s in-built instance scheduler has multiple shortcomings as seen here. A few of which we are:

  • An instance schedule is specific to a region and you can only attach it to instances in that region.
  • Each VM instance can be associated with only one instance schedule.
  • The instance schedule needs a window of about 15 minutes to the time that you have specified to complete the start and stop of the instance.
  • You cannot edit instance schedules. To change an existing one, you need to remove it, delete it, then create/attach a new one

Our Alternative to Google’s Instance Scheduler

Pawa IT Solutions has built a custom script that addresses the pitfalls that come with Google’s instance scheduler.The script comes in to resolve this without relying on 3rd party management tools or chaining a junior admin to the keyboard for a 6 AM wake-up call, to start the server and shut it down at 6 PM in the evening.

Here’s how:

  • With the Google Apps Script dashboard, we can manage and monitor multiple VMs/ project functions, including the bound scripts attached to your VM . This lets anyone with access, control the state of these VMs without getting into the Cloud Console.
  • The start and stop functions are scheduled to run at fixed intervals, hence no delay in starting or stopping the VM. 
  • The script can be edited, unlike the instance scheduler. This ensures  modification/customizations to fit an organization’s needs and varying scenarios.
  • There are logs in each of the cloud functions, that show all the previous and current running executions. In case of failure/error, we have connected the script to an email account for notification.
  • There are no limitations when it comes to the region of the instance and an instance in any region can be attached to the script.

The script uses a serverless execution environment in Google cloud called cloud functions. Cloud functions allow you to host your code and small functions/anything that you want to execute, based on triggers, such as uploads to Google cloud storage, pub/sub messages, or HTTPS invocations. In this case, we are invoking cloud functions with an HTTP request by creating an HTTP endpoint for the function by specifying the -‘-trigger-http’ type when deploying the function. Once the cloud function is created with the HTTP trigger, it generates a URL that is used to invoke the start or stop function.

The requirements to execute are:

  • You need to have a GCP project
  • Billing must be enabled
  • Cloud functions and cloud build APIs must be enabled
  • For control and security, a dedicated service account with sufficient permissions set to compute instance ‘admin v1’, to have full control over compute engine instance groups, disks, snapshots, and images. This permission gives read access to all compute engine networking resources.

Technical Overview

Schedule Virtual Machine Instances on Google Cloud
Auto-schedule VMs on Google Cloud

Expected Outcome and Costs Savings

Due to the nature of this function, ( you only request it when you want to start or stop a server), there may be little/ no charges at all. See how we helped our customer running over 12 Google Cloud Projects.

“For  the QuickBooks related projects, all virtual machines were set to start at 7:00 AM and stopped at 6:00 PM every day. This resulted in them getting billed for just 11 hours a day instead of 24 hours.”

“Cloud computing is the FUTURE and with proper support, technical know-how, and leverage on GCP from partners such as PAWA IT, the FUTURE just got curious” – Emmanuel Wabala, CEO and QuickBooks Pro Consultant/Advisor.


Paying for the virtual machines’ costs during the off-hours is simply unnecessary. We can optimize your resources and reduce costs significantly by implementing auto-shutdown and auto–startup in GCP by scheduling the machines to run at specified times. This policy and configuration, provide a flexible option to optimize your virtual machines based on demand and reduce the overall cost, significantly.