繁体   English   中英

无服务器框架,Google Cloud Functions和Firestore事件触发器

[英]Serverless Framework, Google Cloud Functions & Firestore Event Triggers

使用无服务器框架,是否可以从Firestore事件中触发Google Cloud Function?

我正在使用Google Cloud Functions +无服务器框架,并且试图确定无服务器框架是否支持firestore-events。

我想使用Cloud Firestore触发器,但是不确定是否支持,如果不能,那么我如何在serverless.yml文件中正确指定事件?

当对文档进行任何更改时应触发事件的函数示例。 从这里: https//firebase.google.com/docs/functions/firestore-events

注意:我将Firebase中的函数导入一个单独的文件中,然后将其导入到index.js中。

exports.firestoreEvents = functions.firestore
   .document(‘users/marie’).onWrite((change, context) => {
     // ... Your code here
   });

如果支持,如何在serverless.yml中配置它?

 firestoreEvents:
   handler: firestoreEvents
   events:
     - event:
       ????

要在更改Firestore文档时触发功能,您应该在serverless.yml文件中编写如下代码:

myFunction:
  handler: myFunction
  events:
    - event:
        eventType: providers/cloud.firestore/eventTypes/document.update
        resource: projects/<project-id>/databases/(default)/documents/<path-to-document>

我写了一篇关于如何在Firebase触发器上使用无服务器框架的文章: https ://medium.com/ponce-agtech/using-firebase-triggers-in-serverless-framework-ad99594b86fa

希望能帮助到你 ;)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM