amazon s3
aws s3 cli is great! You can easily move your local files to your aws s3 buckets. However, sometimes it is not that easy to do simple tasks - like copy files where there is a whitespace in the file name, delete all versions of all files in a versioned s3 bucket and the difference between aws s3 sync
and aws s3 cp --recursive
.
escape the whitespace in your file name
When you have a long list of files that you need to upload to s3 bucket, it will be easy for you to loop it through if you have nice filenames that there are no whitespace. Something like this:
However, sometimes it is slightly more complicated when it comes to filenames with whitespace. There is also one command handy - basename
. Something like this:
So if we put it into a bash script loop, it will be something like this:
delete all versions of all files in a versioned s3 bucket
When it comes to delete a versioned s3 bucket, you will need to delete all versions of s3 bucket objects before you can delete the s3 bucket. So let’s wrap a simple script to do it. You will use aws s3
command and jq
. If you don’t know anything about jq. You can check my last post on jq.