[英]How to setup lifecycle to delete folders under s3 bucket using boto3
[英]Delete files under S3 bucket recursively without deleting folders using python
我收到错误消息,当我尝试删除特定文件夹下的所有文件时,问题就在这里 ['Key': 'testpart1/ . '] 另外我想删除 30 天前的文件,请帮我写脚本
import boto3
s3 = boto3.resource('s3')
my_bucket = s3.Bucket('my-bucket')
response = my_bucket.delete_objects(
Delete={
'Objects': [
{
'Key': 'testpart1/*.*' # the_name of_your_file
}
]
}
下面的代码将递归删除前缀下的所有文件:
import boto3
s3 = boto3.resource('s3')
my_bucket = s3.Bucket('my-bucket')
response = my_bucket.objects.filter(Prefix="testpart1/").delete()
请检查https://stackoverflow.com/a/59146547/4214976以根据日期过滤掉 object。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.