Reduce Google App Engine Flex Costs with Cloud Scheduler, Cloud Functions and the GAE Admin API
Google App Engine Flex can run most docker workloads, for instance, it is able to run headless Unity linux builds unlike Google Cloud Functions or Cloud Run which are on the gVisor runtime. However, you cannot scale-to-zero, which usually implies a GAE flex application will cost you around $50 a month. This is too expensive if I only need it running occasionally but over a long time period.
In Corepox’s case we evaluate a ship’s strength by battling against other ships. We regularly get new ships, but we don’t need to run battles 24/7. Instead, running benchmarking battles twice a day for one hour is enough. This is potentially a 12x cost reduction to less than $5 per month!
To do this I use a Google Cloud Scheduler job firing once every hour, notifying a Cloud Pub/Sub topic, that triggers a Google Cloud Function. The Cloud function, using ambient authentication (no keys to manage!), calls the Google App Engine Admin API to:
- List all the versions of a GAE application and find the latest one
- Depending on the hour of the day, either sets the servingStatus field to STOPPED or SERVING via a PATCH request
Voila, my GAE usage graphs. Money saved!

Discussion