【发布时间】:2021-03-22 21:43:39
【问题描述】:
我有如下路径:
s3://edl-landing/lu/hello2/
下面有两张表,如下图:
现在,我想删除10th and 11th November 的数据。所以,下面是我使用boto 客户端的python 代码,但它不会从S3 中删除对象。我没有收到任何错误。另外,我尝试了this link 的各种解决方案,但它也没有从 S3 中删除实际数据。
prefix = "lu/hello2/"
s3 = boto3.resource('s3')
bucket = s3.Bucket(name="edl-landing")
FilesNotFound = True
blankList=[]
for obj in bucket.objects.filter(Prefix=prefix):
#print(obj.key)
blankList.append(obj.key.split('/')[2])
blankList = set(blankList) // 2 names
while ("" in blankList):
blankList.remove("")
datesList = ['2020-11-10','2020-11-11']
for i in blankList:
for j in datesList:
path = "s3://edl-landing/lu/hello2/"+i+"/edl_load_ts="+j+"/"
print(path)
bucket.objects.filter(Prefix=path).delete()
print("All the objects have been deleted for the mentioned dates...")
我哪里错了?我通过 EC2 实例运行它。
【问题讨论】:
标签: python amazon-web-services amazon-s3 amazon-ec2