【问题标题】:Is it possible to create gcp bucket that deletes themselves after a period of time?是否可以创建一段时间后自行删除的 gcp 存储桶?
【发布时间】:2021-03-26 10:06:22
【问题描述】:

谷歌云 API 或 python 库中是否有命令允许创建一个临时存储桶,其年龄作为参数?

我看到存储桶提供Object Lifecycle Management,但似乎这些规则适用于存储桶内的 blob,但不适用于存储桶本身。

【问题讨论】:

    标签: google-cloud-platform bucket ttl


    【解决方案1】:

    不,您不能自动删除存储桶。实际上,您可以设置一个生命周期来自动删除 blob,而不是存储桶本身

    如果您必须在接下来的 365 天内删除存储桶,您可以使用 Cloud Scheduler。

    运行此命令

    gcloud scheduler jobs create http delete-bucket \
      --oauth-service-account-email=<service account email>  \
      --http-method=DELETE --schedule="0 0 * * *" --time-zone=UTC \
      --uri=https://storage.googleapis.com/storage/v1/b/<your bucket name>
    

    在这个命令中我调用Storage DELETE api,你可以根据this expression设置一个时间表 -> 你可以指定月份和日期,因此,最多到下一年,而不是更多。

    您还需要有一个具有 storage.bucket.delete 权限的服务帐户(存储管理员角色)

    【讨论】:

    • 谢谢!我去查一下!
    猜你喜欢
    • 2022-10-13
    • 1970-01-01
    • 2017-01-23
    • 2021-05-10
    • 1970-01-01
    • 1970-01-01
    • 2021-02-22
    • 2020-09-30
    • 2020-03-22
    相关资源
    最近更新 更多