mentics
mentics

Reputation: 6999

From Python code, how can I simulate a storage event to a Google Eventarc topic?

Setup:

  1. Deploy a google cloud run service that simply logs exactly its POST payload
  2. Create an eventarc that triggers when an object is finalized in a storage bucket that calls that cloud run service endpoint

That all works normally. Now, I know of two options to simulate an event (other than rewriting files which is not "simulating" and not acceptable for this case):

  1. PubSub API

It's straightforward to publish a message to the Eventarc trigger's topic. However, whenever I do that, the payload that arrives at the cloud run service is an envelope wrapping a base64 encoded payload. Eventarc is somehow avoiding that envelope because when it triggers, the payload is just the CloudEvents JSON. Is there some setting in the PubSub API to get rid of this envelope or something?

  1. EventArc Publishing API

The problem here is that it is a google sourced event. So there is no channel. But the API requires a channel to be specified. I tried various formats for the channel but could find nothing that worked. The one possibility is if I set the channel to "google" then I get a 403 permission denied on resource project google. If that is supposed to work, exactly what permissions are required? The docs mention eventarc.publisher which I granted but perhaps I missed giving it to the correct service account?

Upvotes: 0

Views: 123

Answers (1)

mentics
mentics

Reputation: 6999

I realized that the answer is don't bother trying to simulate the same event. Just create a different eventarc that listens on a pubsub topic and publish to that. Unfortunately, it still has the message wrapped in an envelope when it calls the service, so I had to create a separate endpoint that unwraps the envelope.

Upvotes: 0

Related Questions