【发布时间】: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