jonny_
jonny_

Reputation: 1

Wrong collection error when deploying gcloud function

I run this function deployment command (Gcloud CLI)

gcloud functions deploy function_name \
        --runtime python37 \
    --trigger-resource="gs://<bucket-name>/files/**/*.json" \
    --trigger-event=google.storage.object.finalize

I am trying to deploy a cloud function that triggers when an object is uploaded to a directory in google storage.

Every deployment I have tried, in all their variations, has failed due to one of the errors below.

The above CLI deployment command fails with:

ERROR: (gcloud.functions.deploy) wrong collection: expected [storage.objects], got [storage.buckets], for path [gs:///files/**/*.json]

Out of curiosity, I tried using this trigger event (though, I've seen no support for it):

--trigger-event=google.storage.buckets.finalize

When I use it, and some other variations, this error appears: Problems:

event_trigger.resource: GCS bucket resource gs:///files/**/*.json does not match the expected pattern, which is projects/{project}/buckets/{bucket}

Other Things I Tried

  1. gen2 deployment with the appropriate gen2 trigger event name (FAILED)
  2. gcloud storage ls <wildcard_bucket path> to make sure I was getting the files expected from this path (SUCCESS)
  3. Checked I have permission access to write, create, delete storage objects (SUCCESS)

Upvotes: 0

Views: 268

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317750

You can't use object path wildcards in a Cloud Storage trigger to select which files apply to the trigger. From the documentation:

When you specify a Cloud Storage trigger for a function, you choose an event type and specify a Cloud Storage bucket. Your function will be called whenever a change occurs on an object (file) within the specified bucket.

The trigger is invoked on any object within the bucket. If you don't want that behavior, you must write code in your trigger to check the path and decide if you want the trigger to continue.

You might want to follow along with the tutorial to see how it works.

Upvotes: 1

Related Questions