serverless / serverless-google-cloudfunctions

Serverless Google Cloud Functions Plugin – Adds Google Cloud Functions support to the Serverless Framework
https://www.serverless.com
MIT License
271 stars 126 forks source link

Cloud Storage event #93

Open andypmw opened 6 years ago

andypmw commented 6 years ago

I need to create a Google Cloud Function triggered by Cloud Storage event. I have checked documentations at Serverless.com and GitHub issues at this repository, and can't find any clue to use Cloud Storage event.

So, any help?

jbutz commented 6 years ago

I've not used functions with events, but here is the documentation that will show you how to connect a function to a particular Pub/Sub topic.

I don't think serverless can help you setup Google Cloud Storage to trigger an event, but so long as you setup Storage to publish the event to the topic you configure for the function I think it should all work.

ykt commented 6 years ago

Hi I think you could do it like this;


functions:
  myfn:
    events:
      - event:
        eventType: google.storage.object.finalize
        resource: projects/<project-id>/storage/name
aadikill commented 5 years ago

@ykt you comment really helped me a lot. Thank You. I tried above code with a small change and it is working now.

instead of resource: projects/<project-id>/storage/name

use

resource: projects/<project-id>/buckets/<bucket-name>

It was throwing an error like below Error: Deployment failed: RESOURCE_ERROR {"ResourceType":"cloudfunctions.v1beta2.function","ResourceErrorCode":"400","ResourceErrorMessage":{"code":400,"message":"The request has errors","status":"INVALID_ARGUMENT","details":[{"@type":"type.googleapis.com/google.rpc.BadRequest","fieldViolations":[{"field":"event_trigger.resource","description":"GCS bucket resource projects/<project-id>/storage/<bucket-name> does not match the expected pattern, which is projects/{project}/buckets/{bucket}"}]}],"statusMessage":"Bad Request","requestPath":"https://cloudfunctions.googleapis.com/v1beta2/projects/<project-id>/locations/us-central1/functions","httpMethod":"POST"}}

amar02041988 commented 5 years ago

Just wanted to know how to mention the bucket prefix(specific folder within the bucket) for which i need to set the trigger in serverless.yml function section to read the object create event from a specific folder rather than on whole bucket. I didn't find in the serverless.com documentation for google cloud.

Any help is appreciated!!