0

I have an S3 bucket with roughly a thousand folders. Inside each folder, I want to copy a file to a new folder a level in. Something like:

foreach (folder in myBucket){
  cp folder/myFile.abc folder/myNewFolder/myFile.abc;
}

How can I execute this one-off logic in S3?

4

1 回答 1

0

我最终只使用了 bash 和亚马逊自己的 CLI

BUCKET=myBucketName
for dir in $(aws s3 ls $BUCKET | awk '{print $2}'); do
    aws s3 cp s3://$BUCKET/${dir}myFile.abc s3://$BUCKET/${dir}myNewFolder/myFile.abc
done

aws s3 ls不包含任何有用的标志来修改其输出,因此我曾经awk切断目录输出附带的“PRE”。

将上述内容放入myScript并使用bash myScript.

于 2014-08-27T15:52:08.550 回答