Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Eventarc: Trigger Cloud Run services with events from Google Cloud

Eventarc: Trigger Cloud Run services with events from Google Cloud

Eventarc is a eventing product that allows you to trigger Cloud Run services from Google Cloud sources. In this talk, we'll get a tour of Eventarc features and see some event-driven Cloud Run demos powered by Eventarc.


Mete Atamel

April 15, 2021


  1. Eventarc:Trigger Cloud Run services with events from Google Cloud Mete

    Atamel Developer Advocate Google Cloud
  2. What is Eventarc?

  3. Proprietary + Confidential A new way of getting events to

    managed Cloud Run services Private alpha since early 2020 as Events for Cloud Run Public beta since Oct 2020 as Eventarc GA since Q1 2021 Eventarc
  4. Eventarc - Vision

  5. Eventarc - Current State

  6. Proprietary + Confidential An image is added to Cloud Storage

    bucket → Cloud Run uses Vision API to analyze the image A BigQuery job is completed → Cloud Run sends an email notification using SendGrid A Compute Engine VM is created → Cloud Run adds a label the VM Some use cases
  7. Don’t we already have Pub/Sub?

  8. Proprietary + Confidential Eventarc with its AuditLog and Pub/Sub integration

    potentially allows more integration Eventarc’s trigger is a higher level abstraction Users can manage all their triggers in one place in Eventarc Eventarc vs. Pub/Sub
  9. How do I use Eventarc?

  10. Proprietary + Confidential Create a trigger for new object creation

    in Cloud Storage → Cloud Run gcloud eventarc triggers create trigger-auditlog \ --destination-run-service=${SERVICE_NAME} \ --destination-run-region=${REGION} --event-filters="type=google.cloud.audit.log.v1.written" \ --event-filters="serviceName=storage.googleapis.com" \ --event-filters="methodName=storage.objects.create" \ --event-filters=${PROJECT_NO}-compute@developer.gserviceaccount.com gcloud - AuditLog
  11. Proprietary + Confidential Create a trigger for Pub/Sub messages →

    Cloud Run gcloud eventarc triggers create trigger-pubsub \ --destination-run-service=${SERVICE_NAME} \ --destination-run-region=${REGION} --event-filters="type=google.cloud.pubsub.topic.v1.messagePublished" --transport-topic=projects/${PROJECT_ID}/topics/${TOPIC_ID} gcloud - Pub/Sub
  12. Proprietary + Confidential Cloud Console - Trigger section of Cloud

  13. How do services consume CloudEvents from Eventarc?

  14. POST / HTTP/1.1 Content-Type: application/json; charset=utf-8 Content-Length: 33 ce-specversion: 1.0

    ce-type: google.cloud.pubsub.topic.publish ce-time: 2020-09-05T03:56:24Z ce-id: 1234-1234-1234 ce-source: mycontext/subcontext custom-attr: 42 { "message": "Hello Cloud Next!" } CloudEvents cloudevents.io "Data" "Context"
  15. Cloud Run Service CloudEvent SDK HTTP request → CloudEvent in

    your language cloudevents.io Google Events Library Type library for CloudEvent#data Event parsing libraries HTTP POST to Run URL HTTP body is a CloudEvent with event data. ("binary" CloudEvent V1) (optional) (optional) github.com/googleapis/google-cloudevents
  16. const { HTTP } = require("cloudevents"); const {toLogEntryData} = require('@google/events/cloud/audit/v1/LogEntryData')

    app.post('/', async (req, res) => { // Read CloudEvent using CloudEvents SDK const cloudEvent = HTTP.toEvent({ headers: req.headers, body: req.body }); // Read AuditLog using Google.Events library for Node.js const logEntryData = toLogEntryData(cloudEvent.data); // Extract bucket and objectName const tokens = logEntryData.protoPayload.resourceName.split('/'); const bucket = tokens[3]; const objectName = tokens[5];
  17. using CloudNative.CloudEvents; using Google.Events; using Google.Events.Protobuf.Cloud.PubSub.V1; public async Task<CloudEvent> Read(HttpContext

    context) { // Read CloudEvent using CloudEvents SDK var cloudEvent = await context.Request.ReadCloudEventAsync(); // Read Pub/Sub message using Google.Events library for .NET var messagePublishedData = CloudEventConverters.ConvertCloudEventData<MessagePublishedData>(cloudEvent); // Extract the Pub/Sub message var pubSubMessage = messagePublishedData.Message;
  18. Proprietary + Confidential Quickstart cloud.google.com/eventarc Codelab: Trigger Cloud Run with

    events from Eventarc codelabs.developers.google.com/codelabs/cloud-run-events Thank you