【发布时间】:2020-12-12 07:34:33
【问题描述】:
我不熟悉编写脚本和编写 Shell 脚本以将 AWS S3 对象从一个 AWS 账户存储桶复制到另一个存储桶?管道将 zip 文件 (.zip) 上传到存储桶。 shell 脚本应该只复制最后修改的对象(文件)。我知道在 shell 脚本中,您可以递归地根据通配符匹配查找文件并从 S3 CLI 获取最后上传的对象。有没有更优雅有效的方法?
# Normal way of copying from one bucket to another
aws s3 cp s3://source-bucket/object-v2.2.7.zip s3://destination- bucket/.
# Using the --recursive parameter to copy file
aws s3 ls $source-bucket --recursive | sort | tail -n 1 | awk '{print $4}'
get_object = `aws s3 ls $source-bucket --recursive | sort | tail -n 1 | awk '{print $4}'`
aws s3 cp s3://$get_object s3://destination-bucket
echo 'Successfully uploaded file to Destination Bucket'
【问题讨论】:
-
请注意,列出一个大桶中的所有对象是一项缓慢且昂贵的操作,并且不保证 s3 在写入一致后被读取。
-
@DanielFarrell 很高兴知道,您对如何更优雅地执行此操作有什么建议吗?
标签: bash amazon-web-services shell amazon-s3 scripting