Roshan Upreti
Roshan Upreti

Reputation: 2052

Is it possible to include multiple buckets as --trigger-resource for a google cloud function?

Is it possible to include two buckets as -trigger-resource for a gcloud function? I tried the following deployment, but it only seems to be listening to events occuring in the bucket-2.

gcloud functions deploy my-function \
--entry-point functions.MyFunction \
--runtime java11 \
--memory 512MB \
--trigger-resource gs://bucket-1 \
--trigger-resource gs://bucket-2 \
--trigger-event google.storage.object.finalize \
--allow-unauthenticated \
--region=europe-west1

Would appreciate any sort of help.

Upvotes: 5

Views: 1916

Answers (2)

Doug Stevenson
Doug Stevenson

Reputation: 317467

A single deployed function can only trigger on changes to a single bucket at a time. If you want to trigger on multiple buckets, you can deploy the function once for each bucket. You will have to give each function a different name and --trigger-resource flag, but everything else can stay the same.

Upvotes: 8

Emil Gi
Emil Gi

Reputation: 1168

As documentation doesn't suggest such option as multiple trigger resource it is not possible I believe.

If you don't want to create extra functions you can receive bucket notifications in Pubsub and trigger your function on Pubsub events.

Upvotes: 2

Related Questions