Aws S3 CLI entire folder download to local

Viewed 1658

Is there a aws cli command that allows to download an entire folder from s3 to local machine, instead of creating a folder locally.

For example , when i run the following command

aws cp s3 s3://<MY-BUCKET>/folder1 . --recursive

I expect the "folder1" to downloaded to my local machine along with its contents.

Thanks in advance

2 Answers

If you want it to copy folder1/, you could use:

aws s3 cp s3://<MY-BUCKET>/ . --recursive --exclude '*' --include 'folder1/*'

This tells it to copy the root directory, but only include folder1/*.

See: AWS CLI - Use of Exclude and Include Filters

You can use the sync method of the s3 cli

aws s3 sync s3://<MY-BUCKET>/folder1 . 

if you really need the folder, you could do something like

mkdir ./folder1
aws s3 sync s3://<MY-BUCKET>/folder1 ./folder1 
Related