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
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 )
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.
The above resource events can be tagged into two categories
- Background Functions ( Cloud Storage / Cloud Pub/Sub )
- HTTP Functions ( Web hook / HTTP Requests )
Cloud Functions support below languages
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
- Event Type
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