更新AWS S3对象密钥(密钥名称)



我需要重命名存储在AWS S3存储桶中的大量文件。每个文件/对象将单独重命名(基于某些条件 - 没有常见的"前缀/后缀")。我想到了" Current_filename"one_answers" new_filename"的列表,可以将CLI执行为.bat文件/队列。

是否可以通过CLI或编程性地仅更新AWS S3存储桶中的对象键(密钥名称),而无需以下复制/移动文件:

aws s3 cp s3://mybucket/folder/myfilename.jpg s3://mybucket/folder/my_NEW_filename.jpg

我可以将所有其他对象保持相同,但是文件名(密钥名称)必须更改。

您还可以使用AWS S3 Move命令将文件移至新名称而不是复制和删除文件。AWS S3移动

# AWS Example
aws s3 mv s3://mybucket/test.txt s3://mybucket/test2.txt
# Copy file from local to S3
aws s3 cp robots.txt s3://ascisolutions.com
# Rename/move file
aws s3 mv s3://ascisolutions.com/robots.txt s3://ascisolutions.com/robots.txt.bak
# Move file to a directory in S3
aws s3 mv s3://ascisolutions.com/robots.txt.bak s3://ascisolutions.com/test/robots.txt.bak
# Rename/move file
aws s3 mv s3://ascisolutions.com/test/robots.txt.bak s3://ascisolutions.com/test/robots.txt
# Move file back to root directory of S3 bucket
aws s3 mv s3://ascisolutions.com/test/robots.txt s3://ascisolutions.com/robots.txt

Amazon S3中的对象/文件是不可变的,不能附加到或 改变了。为了模拟附加,您需要编写 再次使用其他数据。

您需要复制到另一个对象以更改其名称。如果您在S3存储桶之间移动而不是在本地复制并返回。

将是有效的。

我们遇到了类似的情况,我将如何更改所有文件。您需要找到分组所有S3键并执行重命名的模式。这是分布式系统的美丽。

我们以日期/小时/15分钟的模式存储。我们能够通过CLI同时重命名

通过同时重命名。

希望它有帮助。

最新更新