【问题标题】:Can google cloud functions listen to multiple event triggers?谷歌云功能可以监听多个事件触发器吗?
【发布时间】:2019-12-29 03:53:36
【问题描述】:

我目前正在尝试使用REST API 部署一个谷歌云功能,以便监听谷歌云存储桶的更改/删除。

但是,我注意到我只能指定一个EventTrigger

{
  "name": string,
  "description": string,
  "status": enum (CloudFunctionStatus),
  "entryPoint": string,
  "runtime": string,

  ...

  "sourceUploadUrl": string
  // End of list of possible types for union field source_code.

  // Union field trigger can be only one of the following:
  "httpsTrigger": {
    object (HttpsTrigger)
  },
  "eventTrigger": {
    object (EventTrigger)
  }
  // End of list of possible types for union field trigger.
}

我的选项如下choices

google.storage.object.finalize

google.storage.object.delete

google.storage.object.archive

google.storage.object.metadataUpdate

如果我想收听多个触发器(例如 google.storage.object.finalizegoogle.storage.object.delete),会发生什么?

我是否只需要部署多个云功能?

【问题讨论】:

    标签: google-cloud-platform google-cloud-functions gcloud


    【解决方案1】:

    是的,您需要部署多个功能。每个函数只能有一个触发器。

    您可以部署使用相同源的多个配置,或者使用一个触发器来调用另一个函数来聚合不同类型的事件。

    【讨论】:

    【解决方案2】:

    如果您只想处理可用事件的子集,Paul 的回答是正确的。或者,如果您想直接在存储事件上插入函数。

    但是,如果您想全部捕获,或者如果您想在您的函数中选择自己要处理的事件类型,您可以“作弊”。

    确实,您可以publish bucket notification in pubsubplug a function on pubsub events

    【讨论】:

      【解决方案3】:

      实际上是可以实现的,我们公司就是这样做的。

      诀窍是:将您的 Cloud Function / Cloud Run 作为唯一经过身份验证的 http 触发器

      然后你会得到一个 URL(只能通过经过身份验证的 http 请求访问)。

      那么你们两个都可以:

      • 如果您传递 Bearer 令牌(即通过 gcloud auth print-identity-token 获取),则直接调用它(邮递员/其他)
      • pubsub 触发,PUSH 订阅已通过该端点的身份验证。

      请注意,它需要您向您的 PubSub 订阅者授予对该资源的许可,但它确实有效!并使您的功能/服务具有同步和异步行为。

      【讨论】:

      • 如果扩展到更复杂的设置,这听起来绝对是一场噩梦。
      猜你喜欢
      • 2021-10-31
      • 2020-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-04
      • 2023-04-08
      相关资源
      最近更新 更多