AWS CLI – S3 sync management

Posted under » AWS on 4 May 2021

First, make sure you have installed AWS Cli. Then try to list all your s3 buckets. You will realise that it is something like linux and rsync.

$ aws s3 ls

Next choose a bucket and list the objects.

$ aws s3 ls s3://project-seuss

PRE media/
PRE static/

To see the contents of the media folder.

$ aws s3 ls s3://project-seuss/media

taik.jpg

Now lets copy a file from your local folder to AWS s3. For the following examples, I am copying with from a folder.

$ aws s3 cp skype.ico s3://project-seuss/media/

It is important to note the trailing backslash for the directory.

Let's say you want to change the storage class to the cheaper "reduced redundancy".

$ aws s3 cp skype.ico s3://project-seuss/media/ --storage-class REDUCED_REDUNDANCY

Now lets sync your local folder to AWS S3.

$ aws s3 sync . s3://project-seuss/media/

All files and folders will be populated or sync from . to S3. If you want the sync to go from s3 to . then

$ aws s3 sync s3://project-seuss/media/ .

Let's say after a while, you want to delete a file from the folder and want the deletion to be in S3 too.

$ aws s3 sync . s3://project-seuss/media/ --delete

Let's say you want to exclude or include some files.

$ aws s3 sync . s3://project-seuss/media/ --exclude ".git/*"
$ aws s3 sync . s3://project-seuss/media/ --include *.css
$ aws s3 sync . s3://project-seuss/media/ --include *.css exclude *.html

You can move instead of sync but you have to put -r

$ aws s3 mv s3://project-seuss/media/ . --recursive

web security linux ubuntu python django git Raspberry apache mysql php drupal cake javascript css AWS data