Amazon AWS CLI S3 With Auto-Complete
Autocomplete Lesson:
To add the autocomplete feature:
$ echo “complete -C aws_completer aws” >> ~/.bash_profile
$ source ~/.bash_profile
S3 CLI commands
Create a bucket:
$ aws s3 mb s3://test-saurav-123
Remove the bucket:
$ aws s3 rb test-saurav-123
Creating empty files in Linux :
$ touch file{1..10}
Copy a local file to a bucket:
$ aws s3 cp file1 s3://copy-file-saurav/
Copy Everything in local file to a bucket:
$ aws s3 sync . s3://copy-file-saurav/
$ crontab -e
Create a script to save all files to S3 bucket every (x) minutes/hours/days or months
• $ vim sync.sh
• press i for insert
• #!/bin/bash
• $ aws s3 sync /home/ec2-user/Documents/ s3://copy-file-saurav
• Press Esc
• Type :wq! To save and exit
• $ Chmod 500 sync.sh
The above command will make it executable
On command line type this to create a cron job:
$ crontab –e
• press I to insert
• paste: */1 * * * * /home/ec2-user/sync.sh
• The above line will sync files every minute. For every day use:
* */1 * * * /home/ec2-user/sync.sh
• save with :wq!
To exclude a file with certain extension:
$ aws s3 sync /home/ec2-user/Documents/ s3://copy-file-saurav –exclude ‘*.rtf’ –acl
public-read –storage-class STANDARD_IA
To exclude a file with public read permission and put in in s3- IA storage class:
$ aws s3 sync /home/ec2-user/Documents/ s3://copy-file-saurav –acl public-read —
storage-class STANDARD_IA
For further reference visit:
https://docs.aws.amazon.com/cli/latest/reference/s3/index.html
Want more information on how to become Amazon AWS Certified? Learn more!