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

Viewed 753

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.

2 Answers

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.

Related