为存储桶创建 Google Cloud Pub/Sub 订阅?

Create a Google Cloud Pub/Sub subscription for a Bucket?

我没有找到很多关于此的信息 我想创建一个 Pub/Sub subscription 每当存储在名为 numbers.csv 的 GCP 存储桶中的 csv 文件发生变化时my_storage。我能够创建云发布-订阅,但只能在特定时间间隔内发送消息,而不是基于任何事件。我如何设置 Pub/Sub 以便在我的存储桶发生变化时收到消息?谢谢。我读了 GCP documentation 但它令人困惑。

你可以找到官方文档:

Using Pub/Sub notifications for Cloud Storage

请遵循文档中的先决条件步骤,然后应用通知配置。

The following steps add a notification configuration to your bucket that sends notifications for all supported events.

gsutil notification create -t TOPIC_NAME -f json gs://BUCKET_NAME

To send notifications for a subset of events, include the -e flag.

支持的事件有:

OBJECT_FINALIZE 
OBJECT_METADATA_UPDATE
OBJECT_DELETE   
OBJECT_ARCHIVE

编辑

示例: notification - Configure object change notification

创建仅在创建新对象时发送事件的通知配置:

gsutil notification create -f json -t TOPIC_NAME -e OBJECT_FINALIZE gs://example-bucket

要在 gs://your-bucket/numbers.csv 被覆盖时收到 Pub/Sub 通知,请使用此命令:

gsutil notification create -f json \
    -t projects/your-project/topics/your-pubsub-topic \
    -e OBJECT_FINALIZE \
    -p path/to/numbers.csv \
    gs://your-bucket-name