Tue Sep 21 2021·2 min read
Photo by Kane Taylor
To copy the files from a local folder to an S3 bucket, run the
command, passing in the source directory and the destination bucket as inputs.
Let's look at an example, which copies the files from the current directory to an S3 bucket. Open your terminal in the directory which contains the files you want to copy and run the s3 sync command.
aws s3 sync . s3://YOUR_BUCKET
The output shows that the files and folders contained in the local directory were successfully copied to the s3 bucket.
You can also pass the directory as an absolute path, for example:
# on Linux or macOS aws s3 sync /home/john/Desktop/my-folder s3://YOUR_BUCKET # on Windows aws s3 sync C:\Users\USERNAME\my-folder s3://YOUR_BUCKET
--dryrunparameter. This enables us to show the command's outputs, without actually running it.
aws s3 sync . s3://YOUR_BUCKET --dryrun
You might be wondering what would happen if the bucket contains a file with the same name and path as a file in the local folder.
s3 sync command copies the objects from the local folder to the
destination bucket, if:
This means that if we had a
document.pdf file in both the local directory and
the destination bucket, it would only get copied if:
To copy a local folder to a specific folder in an S3 bucket, run the
command, passing in the source directory and the full bucket path, including the
The following command copies the contents of the current folder to a
directory in the S3 bucket.
aws s3 sync . s3://YOUR_BUCKET/my-folder/
The output shows that
example.txt was copied to
I'll send you 1 email a week with links to all of the articles I've written that week