我有一个 S3 路径:
my_bucket/object_1/object_2/object-3/object_2023/2023-30-09-15h21/
my_bucket/object_1/object_2/object-3/object_2020/2020-25-11-12h18/
my_bucket/object_1/object_2/object-3/object_2022/2022-03-07-14h22/
my_bucket/object_1/object_2/object-3/object_2023/2023-24-11-15h21/
我正在选择包含最后创建的对象的路径,例如:
my_bucket/object_1/object_2/object-3/object_2023/2023-24-11-15h21/
我已经创建了一个小脚本来选择对象:
object_2023
,我正在寻找一个解决方案来选择2023-24-11-15h21/
来构建所有路径:
my_bucket/object_1/object_2/object-3/object_2023/2023-24-11-15h21/
请问您有解决方案吗?我该怎么做? 谢谢
session_root = boto3.Session(region_name='eu-west-3', profile_name='my_profile')
s3_client = session_root.client('s3')
var1 = "object_1/object_2/object-3/"
var2 = "object_"
currentYear = str(date.today().year)
#print(currentYear)
var3 = "".join([var2, currentYear]) #object_2023
#print(var2)
var4 = "".join([var1, var3]) #object_2/object_2023/
#print(var4)
var5 = "/2023-24-11-15h21/"
prefix = "".join([var4, var5])
print(prefix)
我不确定,但也许您需要将文件上传到已经存在的文件夹中
s3 = boto3.resource('s3')
s3.Bucket('bucketname').upload_file('file','folder/object_1/object_2/object-3/object_2023/2023-24-11-15h21/')