Do you have some code that needs to be run regularly? Read along to learn how to do this using a serverless function on the google cloud platform (GCP).

As a data scientist/engineer, I often have code that needs to run periodically. This could be anything from processing some log files every day at 02:00 pm or running a machine learning model every day at 01:00 am.

If it can run within a memory limit of  8 GiB and in under 9 minutes, then it’s probably worth implementing it as a serverless function.

If that’s of interest to you, then in this article, I will show you how to schedule your code using a serverless architecture, utilizing the Cloud Functions serverless compute product from Google Cloud Platform (GCP).

To learn more about Google Cloud Functions and its benefits, check out my other article on Medium. The first section explains it in a concise way. 😄

⚠️ Housekeeping ⚠️

This article assumes you already have a GCP account. If you don’t have one, signup _ here_ which comes with some free credits.

If you want to interact with your GCP account from your local machine, install the Google Cloud SDK using the steps outlined_ here__._

Make sure to enable APIs for Google Cloud Storage, Functions, Pub/Sub, and Scheduler, in your GCP project using the API console.

All the code in this article was developed in Python 3.8. All the code necessary is made available via GitHub Gist.

Example Task & Solution Architecture

So, what are we building? For the purposes of this article, we are going to schedule a cloud function that prints money every 15 minutes. Not literal money of course 😄, but the word money.

Cloud solution architecture. (source: author)

#machine-learning #serverless

How to Schedule a Serverless Google Cloud Function to Run Periodically
1.40 GEEK