Search code examples
amazon-web-servicesamazon-s3aws-cli

copying files between s3 buckets without folders amazon aws cli


I'm looking through the documentation of aws cli and I cannot find the way to copy the only files in some directory structure to other bucket with "flattened" structure(I want one directory and all files inside of it).

for example

/a/b/c/1.pg
/a/2.jpg
/a/b/3.jpg

i would want to have in different bucket:

/x/1.jpg
/x/2.jpg
/x/3.jpg

Am I missing something or is it impossible? Do you have an idea how could I do that?


Solution

  • You don't need to download files locally, as suggested in another answer. Instead, you could write a shell script or something that does the following:

    • Run ls on s3://bucket1 to get fully-qualified names of all files in it.
    • For each file, run cp to copy it from current location to s3://bucket2/x/