'Aws S3 CLI entire folder download to local

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



Solution 1:[1]

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

Solution 2:[2]

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 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 John Rotenstein
Solution 2