Search code examples
google-cloud-platformgoogle-cloud-datastoregoogle-cloud-functionsdatastore

Create/update in datastore triggers Cloud function


I have a database in Google Datastore. I don't know how to use cloud functions, but i want to trigger an event after a creation or an update. Unfortunately the documentation is light on the subject : https://cloud.google.com/appengine/docs/standard/java/datastore/callbacks

I don't know how i could use @PostPut to trigger an event as soon as a line is created or updated.

Does anyone have a tutorial which a basic example ?

thank you


Solution

  • Dan MacGrath provided an answer to a similar request (callbacks are indeed discussed below. Such solution doesn't exist yet. As a workaround, taking into account the current available triggers:

    1. HTTP—invoke functions directly via HTTP requests.
    2. Cloud Storage
    3. Cloud Pub/Sub
    4. Firebase (DB, Storage, Analytics, Auth)
    5. Stackdriver Logging—forward log entries to a Pub/Sub topic by creating a sink. You can then trigger the function.

    I would suggest a couple of solutions:

    1. Saving something in a specific bucket from Cloud Storage every time that a line is created or updated to trigger a linked Cloud Function. You can delete the bucket contents afterwards.
    2. Create logs with the same name and then forward them to Pub/Sub, by creating a sink.

    EDIT 1

    • Cloud Storage triggers for Cloud Functions: Official Google doc and tutorial with a sample code in node.js 6 in Github.
    • Cloud Pub/Sub triggers for Cloud Functions: Official Google doc and tutorial with a sample code in node.js 6 in Github (the same than before).