在 GCP 存储桶中创建对象时触发通过 Cloud Run 部署的数据流作业

问题描述

我创建了一个数据流管道,它从 GCS 存储桶中读取文件并对其进行处理。当我从本地执行作业时,它正在工作。

我使用 storage.object.create 上的触发器在 Cloud Run 中部署了数据流作业。

但是当我上传 GCS 存储桶中的任何文件时,未执行的日志或数据流作业中没有显示发消息

触发器配置

Ingress:Allow traffic
Authentication:Allow authentication
Event source:Cloud Storage
Event type:google.cloud.audit.log.v1.written
Create time:2021-02-12 (16:05:25)
Receive events from:All regions (global)
Service URL path:/
Service account:sdas-pipeline@sdas-demo-project.iam.gserviceaccount.com
Service name:storage.googleapis.com
Method name:storage.objects.create

在这里错过了什么?请提出建议。

解决方法

您的 Cloud Run 服务未触发的原因是,每当创建/上传对象到您的存储桶时,都可能没有写入审核日志。每当事件写入审核日志时都会启动 Eventarc 触发器,默认情况下,Cloud Storage 处于禁用状态:

解决方案是为 Cloud Storage 启用审核日志。可以通过两种方式完成:

  1. 在您第一次创建 Eventarc 触发器时启用它。 enter image description here
  2. 或转至IAM 和管理 > 审核日志,并确保检查所有字段以使用 Cloud Storage: enter image description here

作为参考,可以在首页 > 活动上查看审核日志,示例如下:

enter image description here