Cloud Recommender and Shutdown Scripts for the PCA Exam

GCP Study Hub
Ben Makansi
March 28, 2026

Cloud Recommender and shutdown scripts are two small but exam-relevant Compute Engine topics that the Professional Cloud Architect exam likes to ask about. They are easy points if you know what each one does and where it shows up. I will walk through both, starting with Cloud Recommender.

Cloud Recommender in Compute Engine

Cloud Recommender is an AI-powered optimization tool that identifies inefficient resources across Google Cloud. It is technically its own service with its own API, and it surfaces recommendations for many different products. On the Professional Cloud Architect exam, though, Compute Engine is where it tends to come up.

There are two use cases worth knowing for Compute Engine.

The first is finding idle VM instances. Cloud Recommender analyzes utilization data and flags virtual machines that are sitting around doing nothing. These are the zombie instances that nobody remembers spinning up but that keep billing every hour. Once you have the list, you can stop or delete them. The gcloud command for pulling that list is:

gcloud recommender recommendations list --recommender=google.compute.instance.IdleResourceRecommender

The second use case is rightsizing recommendations. Cloud Recommender looks at historical CPU and memory usage on a VM and tells you whether the machine type is too big or too small for the actual workload. If you are running an e2-standard-8 but only ever use one vCPU, the recommender will suggest dropping down to a smaller machine type. The opposite also happens, where a VM is constantly pegged and the recommender suggests scaling up.

Both use cases share the same theme. You are letting Google's analysis do the work of identifying waste or mismatch instead of building your own monitoring queries. For the exam, if you see a question about identifying underutilized VMs or right-sizing existing instances based on usage patterns, Cloud Recommender is the answer.

Shutdown scripts

Shutdown scripts are scripts that execute automatically when a VM instance is stopped or terminated. They are useful any time an application needs to clean up before it goes away. That might mean flushing logs to Cloud Storage, releasing a lock, draining connections, saving in-memory state, or notifying another system that the instance is going down.

The mechanic is simple. You write the script in any executable format that the VM's OS can run, so Bash on Linux or PowerShell or a batch file on Windows. Then you attach the script to the instance metadata under the key shutdown-script. When the VM stops, Compute Engine sees that metadata key and runs the script before the instance fully shuts down.

The two timing numbers to remember are 90 seconds and 30 seconds.

If you stop a VM on demand, either through the console or with gcloud compute instances stop, the shutdown script gets up to 90 seconds to finish. If a Spot or preemptible instance is reclaimed by Google, the script gets only 30 seconds. That difference matters because preemption is exactly where shutdown scripts pull their weight. Spot VMs can be taken back at any time, and without a shutdown script you lose whatever in-progress work was happening on that instance. With a 30-second cleanup window, the script needs to be fast and focused. Save what matters, push it somewhere durable, and exit.

The exam tends to test shutdown scripts in two ways. The first is the basic concept of attaching a script via metadata using the shutdown-script key. The second is the pairing with preemptible or Spot VMs, where shutdown scripts are the standard answer for "how do I gracefully handle a VM that can be reclaimed at any moment." If a question describes a workload running on Spot VMs that needs to checkpoint its progress before shutdown, shutdown scripts are what you reach for.

One last thing. Shutdown scripts are not guaranteed to complete. If the OS hangs, or if the script itself takes longer than the time limit, the VM will be terminated anyway. Design accordingly. Write idempotent cleanup logic, do the most important work first, and assume the script may be cut off mid-execution.

My Professional Cloud Architect course covers Cloud Recommender and shutdown scripts alongside the rest of the compute material.

arrow