google cloud python kubernetes service performing action on bucket write

9/29/2021

I am trying to write some python service that will be deployed on kubernetes that does something similar to a cloud function triggered by google.storage.object.finalize action and listening on a bucket. In essence I need to replace a cloud function that was created with the following parameters:

--trigger-resource YOUR_TRIGGER_BUCKET_NAME 
--trigger-event google.storage.object.finalize

however I can't find online any resource on how to do this. What would be the best way for some python script deployed in kubernetes to observe actions performed on a bucket and do something when a new file gets written into it? Thank you

-- DarioB
google-cloud-functions
google-cloud-platform
google-cloud-storage
kubernetes

1 Answer

9/29/2021

You just need to enable pubsub notifications on the bucket to publish to a pub/sub topic: https://cloud.google.com/storage/docs/pubsub-notifications

And then have you python application listen to a subscription on the topic that you picked, either in a pull or push setup: https://cloud.google.com/pubsub/docs/pull.

-- somethingsomething
Source: StackOverflow