GCP Learning Series_ Cloud Functions



Cloud Functions — FaaS ( Function as a Service ) / serverless compute service provided by GCP to handle events generated by GCP resources. It is fully managed service by GCP as shown below.

Developers don’t have to worry about administrative infrastructure

  • runtime environments
  • Security Updates
  • OS Patches
  • Scaling
  • Capacity

Developers can focus on writing softwares

Events, Triggers and Functions

  • Events — particular action happen in GCP ( file upload/archive, message published to pubsub)
  • Triggers ( Responding to an event )
  • Functions ( Functions associated with trigger to handle event )

Supported Events

Cloud Functions support even based driven architecture for the events emitted in GCP. For the event, we can wire or tag a CF to trigger a API or an action as shown in below diagram. It does not support for all events in GCP. It supports below GCP resource events.

HTTP Events

Cloud Storage

Cloud Pub/Sub


Cloud Firestore

The above resource events can be tagged into two categories

  • Background Functions ( Cloud Storage / Cloud Pub/Sub )
  • HTTP Functions ( Web hook / HTTP Requests )

Language Support

Cloud Functions support below languages

Node JS



Java 11

It does not provide support for containers yet. i.e docker images containerized can not be deployed into Cloud Functions.

Deployment of Cloud Functions

Login to Google Cloud Console and click on hamburger menu and choose Cloud Function to create /deploy cloud function

  • Provide Function name
  • Trigger
  • Event Type
  • Resource
  • Runtime

CF can be deployed using gcloud command also

To deploy Cloud Function to handle event when user uploads file into Google Cloud Storage, it can be deployed by providing resource name ( bucket name ) and resource event ( on file upload completion )

gcloud functions deploy cloud_function_test_gcs — runtime python37 — trigger-resource gcs-bucket-test — trigger-event google.storage.object.finalize

Similarly if we need to deploy cloud function to handle pubsub event, it can be defined as below

gcloud functions deploy cloud_function_test_pubsub — runtime python37 — trigger-resource test-topic

For cloud pubsub, there is only one event ( i.e message published ) on the topic, here it is test-topic.


Cloud functions will timeout after one minute, although timeout can be configured to extend up to 9 minutes.

Hence cloud functions are suitable for handling events and should not be applicable for time consuming process.

#GCP #LearningContinues #Serverless

Thank You

Bharathy Poovalingam