Home > Software engineering >  How to move files from EC2 to S3 using AWS CLI ? The files should be deleted from EC2 once transferr
How to move files from EC2 to S3 using AWS CLI ? The files should be deleted from EC2 once transferr

Time:12-03

I setup an SFTP server on Debian EC2 instance. I setup a cron job using aws s3 sync <source dir on EC2> <destination S3 bucket>. I issue is that my EC2 will get full as uploads come in.

Once a file is uploaded to EC2 instance, I want the file to moved to S3 bucket. sync command just copies it and doesn't delete from source. How can I accomplish this?

CodePudding user response:

The aws s3 mv command actually performs a CopyObject() and a Delete.

To move a whole directory, use:

aws s3 mv --recursive localdir s3://bucket-name/

If you want to move the 'contents' of the directory, try:

aws s3 mv --recursive localdir s3://bucket-name/ --exclude "*" --include "localdir/*"

See: mv — AWS Command Reference

  • Related