I have a python script which reads the csv file,create table in bigquery based on data in csv and loads the data into the table on runtime. I want to trigger this script whenever a event occurs like a file arriving on a specified bucket. My Python script is present on vm instance(till now,used to run the script from vm instance). Is there any way to execute this script based on a event trigger ?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
A feature of Google Cloud Storage called 'Object Change Notifications' could come in handy here. This will push a notification to a web hook, where you can use your processing code to handle the event (an example to run this on AppEngine is given here, but you could also implement this as a Flask endpoint for example).
Another option is to use Pub/Sub Notifications in combination with Cloud Storage, in case you are more comfortable with that. You can then use the Pub/Sub Python SDK to listen to a specific topic your events arrive in, and use the code you already wrote to handle these events.