introduction
cloud function
- it's a server-less function running on the GCP, which means you don't have to manage VMs or docker containers
- use cases 👇
- log analysis, trigger the cloud function when ERROR occurs
- automated backup, taking a backup of files at a regular interval
- refer this for more info
pub/sub
- GCP pub/sub enables reliable async communication between microservices/applications with the concept of
topic
,publisher
,subscriber
andmessage
- for more info refer gcp documentation
scheduler
Examples
1. take backup at a regular interval
steps
- create a topic in pub/sub
- go to cloud build & enable services as shown below
- create a GCP cloud function & attach a service account to it
- in the trigger section choose
Pub/Sub triggers
and the topic which you have recently created - now click
next
& choosepython3.8
as a coding language, clear all the code present inside the function & print("hello world") instead - now go to the pub/sub select the topic & send a message manually
- now navigate back to the function, and switch to the
logs
panel, here you should be able to see "hello world" message - go to the scheduler service & create a new job, in frequency write
*
5 times, which means it'll send a message on the interval of 1 min,in target-type selectpub/sub
, select your topic & write your message - now our function will be executed after every minute
- you can write code to read/write files from cloud filestore with python sdk or api, make sure
service account
have sufficient permission
2. Integration with third-party services(github) and APIs
3. Serverless mobile back ends
- cloud.google.com/functions/docs/calling/sto..
- cloud.google.com/functions/docs/calling/rea..
- firebase.google.com/docs/cloud-messaging