Amazon Web Services (AWS) Command Line Interface (AWS CLI) – essential examples to manage buckets and objects

This tutorial explains the basics of how to manage S3 buckets and its objects using aws s3 cli using the following examples

# s3 make bucket (create bucket)
aws s3 mb s3://tgsbucket –region us-west-2
# s3 remove bucket
aws s3 rb s3://tgsbucket
aws s3 rb s3://tgsbucket –force
# s3 ls commands
aws s3 ls
aws s3 ls s3://tgsbucket
aws s3 ls s3://tgsbucket –recursive
aws s3 ls s3://tgsbucket –recursive –human-readable –summarize
# s3 cp commands
aws s3 cp getdata.php s3://tgsbucket
aws s3 cp /local/dir/data s3://tgsbucket –recursive
aws s3 cp s3://tgsbucket/getdata.php /local/dir/data
aws s3 cp s3://tgsbucket/ /local/dir/data –recursive
aws s3 cp s3://tgsbucket/init.xml s3://backup-bucket
aws s3 cp s3://tgsbucket s3://backup-bucket –recursive
# s3 mv commands
aws s3 mv source.json s3://tgsbucket
aws s3 mv s3://tgsbucket/getdata.php /home/project
aws s3 mv s3://tgsbucket/source.json s3://backup-bucket
aws s3 mv /local/dir/data s3://tgsbucket/data –recursive
aws s3 mv s3://tgsbucket s3://backup-bucket –recursive
# s3 rm commands
aws s3 rm s3://tgsbucket/queries.txt
aws s3 rm s3://tgsbucket –recursive
# s3 sync commands
aws s3 sync backup s3://tgsbucket
aws s3 sync s3://tgsbucket/backup /tmp/backup
aws s3 sync s3://tgsbucket s3://backup-bucket
# s3 bucket website
aws s3 website s3://tgsbucket/ –index-document index.html –error-document error.html
# s3 presign url (default 3600 seconds)
aws s3 presign s3://tgsbucket/dnsrecords.txt
aws s3 presign s3://tgsbucket/dnsrecords.txt –expires-in 60
$ aws s3 ls s3://tgsbucket –recursive
2019-04-07 11:38:19 2777 config/init.xml
2019-04-07 11:38:20 52 config/support.txt
2019-04-07 11:38:20 1758 data/database.txt
2019-04-07 11:38:20 13 getdata.php
2019-04-07 11:38:20 2546 ipallow.php
2019-04-07 11:38:20 9 license.php
2019-04-07 11:38:20 3677 servers.txt
$ aws s3 ls s3://tgsbucket –recursive –human-readable –summarize
2019-04-07 11:38:19 2.7 KiB config/init.xml
2019-04-07 11:38:20 52 Bytes config/support.txt
2019-04-07 11:38:20 1.7 KiB data/database.txt
2019-04-07 11:38:20 13 Bytes getdata.php
2019-04-07 11:38:20 2.5 KiB ipallow.php
2019-04-07 11:38:20 9 Bytes license.php
2019-04-07 11:38:20 3.6 KiB servers.txt
Total Objects: 7
Total Size: 10.6 KiB
$ aws s3 presign s3://tgsbucket/dnsrecords.txt
https://tgsbucket.s3.amazonaws.com/error.txt?AWSAccessKeyId=AAAAAAAAAAAAAAAAAAAA&Expires=1111111111
&Signature=ooooooooooo%2Babcdefghijlimmm%3A

Leave a Reply

You must be logged in to post a comment.