Cloud Spanner alert based on a select query

44 views Asked by At

I have a query which I run daily on our database in gcp cloud. The query outputs a count and if the count is greater than zero we have to perform a certain task.

What I am looking for is that how can I generate a email when the count is greater than zero so that I don't have to login to GCP every time. What would be the best approach for the same.

Can I connect to the cloud spanner db from my laptop or do I have to login to GCP every time?

Please help, I am new to GCP.

1

There are 1 answers

0
Knut Olav Løite On

I would recommend that you write a small application that executes the query for you, and then create a Cloud Run Job that is scheduled to run once every 24 hours.

You don't write which programming language(s) you are comfortable with, but there are multiple getting started guides for Cloud Spanner in various languages.

Getting started guides for Cloud Run Jobs can be found here: https://cloud.google.com/run/docs/quickstarts#build-and-create-a-job


If your database is a PostgreSQL-dialect Cloud Spanner database, then there are examples for how you can use a standard PostgreSQL driver with Cloud Spanner in combination with PGAdapter on Cloud Run here: https://github.com/GoogleCloudPlatform/pgadapter/tree/postgresql-dialect/samples/cloud-run