DevOps Peach

GCP Basics · Containers & Serverless – Cloud Run, Cloud Run Functions, GKE and Cloud Build · Lesson 2 of 5

Cloud Run Functions, Eventarc and Cloud Scheduler

Cloud Run functions run small pieces of code in response to HTTP requests or events delivered by Eventarc from Cloud Storage, Pub/Sub, audit logs and more; Cloud Scheduler triggers work on a cron schedule.

Practice interactively →

Cloud Run functions (formerly Cloud Functions) let you deploy just a function; Google builds the container and runs it on Cloud Run. Eventarc delivers events to functions and services.

flowchart LR
  UP["User uploads photo.jpg"] --> GCS["Bucket gs://dl-uploads"]
  GCS -- "object finalized" --> EA["Eventarc trigger"]
  EA --> FN["Function make-thumb"]
  FN --> OUT["gs://dl-thumbs/photo.jpg"]
  CS["Cloud Scheduler 0 2 * * *"] -- "HTTP POST" --> RUN["Cloud Run job or service"]
  %% step UP: A user uploads a photo through the app.
  %% step GCS: Cloud Storage emits an object finalized event when the upload completes.
  %% step EA: An Eventarc trigger filters events by type and bucket and delivers them as CloudEvents.
  %% step FN: The function receives the event, reads the photo and creates a thumbnail.
  %% step OUT: The result goes to another bucket; writing to the same bucket would trigger the function again.
  %% step CS: Cloud Scheduler calls an HTTP endpoint on a cron schedule, authenticated with a service account.

Functions

Eventarc

Source Example event
Cloud Storage google.cloud.storage.object.v1.finalized
Pub/Sub message published to a topic
Cloud Audit Logs any API call that is audit-logged, e.g. a BigQuery job completed
Third-party / custom via Eventarc channels

Delivery is at least once: the same event can arrive twice, so make handlers idempotent (for example, skip if the thumbnail already exists). Turn on retries for transient errors and send poison events to a dead-letter topic.

The trigger’s service account needs roles/run.invoker on the target, and the Cloud Storage service agent needs roles/pubsub.publisher for storage events.

Cloud Scheduler

A managed cron service: HTTP targets (with OIDC tokens for Cloud Run), Pub/Sub targets, retries and time zones.

gcloud functions deploy make-thumb --gen2 --runtime=python312 --region=asia-southeast1   --source=. --entry-point=make_thumb --trigger-bucket=dl-uploads
gcloud scheduler jobs create http nightly --location=asia-southeast1   --schedule="0 2 * * *" --time-zone="Asia/Ho_Chi_Minh" --http-method=POST   --uri="https://report-123456789012.asia-southeast1.run.app/run"   --oidc-service-account-email=scheduler-sa@dl-lab-dev.iam.gserviceaccount.com

When to use what

Need Use
Small glue code reacting to one event Cloud Run function
A full app or API in a container Cloud Run service
Batch work that finishes Cloud Run job (scheduled by Cloud Scheduler)
Fan-out work with rate limits Cloud Tasks or Pub/Sub
Command Meaning
gcloud functions logs read make-thumb --region=… Function logs
gcloud eventarc triggers list --location=… Triggers
gcloud scheduler jobs run nightly --location=… Run a schedule now

Traps: writing output into the triggering bucket creates an endless loop; non-idempotent handlers double-charge or double-send on retries; schedules run in UTC unless you set a time zone.

Practice interactively →