Today, I had a need to download a zip file from S3 . I quickly learnt that AWS CLI can do the job. The AWS CLI has aws s3 cp
command that can be used to download a zip file from Amazon S3 to local directory as shown below.
$ aws s3 cp s3://my_bucket/myzip.zip ./
If you want to download all files from a S3 bucket recursively then you can use the following command
$ aws s3 cp s3://my_bucket/ ./ -- recursive
You can specify your AWS profile using the profile
option shown below.
$ aws s3 cp s3://my_bucket/myzip.zip ./ -- profile test
To download all the files from a folder you can use following command:
$ aws s3 cp s3://my_bucket/my_folder ./ -- recursive
You can also use include
and exclude
options to filter files based on wildcards. For example, let’s suppose you only want to download files with zip extension from a S3 bucket my_bucket
then you can use the following command.
$ aws s3 cp s3://pcl-caps ./ --recursive --exclude "*" --include "*.zip"
There is another great option dryrun
that you can use to see the actions that will be performed without running the command. In the above command, if we add —dryrun
flag then we can see which all files will be downloaded to local directory.
$ aws s3 cp s3://pcl-caps ./ --recursive --exclude "*" --include "*.zip" --dryrun
One thought on “TIL #4: Downloading a zip from S3 to local directory using AWS CLI”