【问题标题】:How to setup lifecycle to delete folders under s3 bucket using boto3如何设置生命周期以使用 boto3 删除 s3 存储桶下的文件夹
【发布时间】:2023-03-31 02:37:02
【问题描述】:

我在创建对象生命周期以使用 boto 3 删除所有超过 2 天的文件夹时遇到问题。 我的s3结构如下:

    S3 bucket name : test
    S3 folders under test bucket : day1, day2, day3
    S3 files under each folder :
    test/day1/file1.txt
    test/day2/file2.txt
    test/day3/file3.txt

我想要一个生命周期来删除所有超过 2 天的文件夹。我想出了一些东西:

    import boto3
    from boto.s3.lifecycle import Lifecycle,Rule,Transitions,Expiration
    s3 = boto3.resource('s3')

    bucket = s3.Bucket('test')
    expiration = Expiration(days=2)
    rule = Rule(id='deletetestfold',status='Enabled', expiration=expiration)
    lifecycle = Lifecycle()
    lifecycle.append(rule)

但是代码的第二部分使用了 boto 而不是 boto3。有没有一种方法可以完成使用 boto3 删除超过 2 天的文件夹的生命周期 对此的任何帮助将不胜感激。

【问题讨论】:

    标签: python python-2.7 amazon-web-services amazon-s3 boto3


    【解决方案1】:

    【讨论】:

    • @errate 没有被弃用?
    • @Austin 啊,直到你提到我才注意到...是时候为这些变化准备我的代码了^^也更新了我的答案:)
    • 为了让对话更清晰:put_bucket_lifecycle 已弃用,但 put_bucket_lifecycle_configuration 没问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-19
    • 2020-12-10
    • 1970-01-01
    • 2022-01-02
    • 1970-01-01
    • 1970-01-01
    • 2018-01-04
    相关资源
    最近更新 更多