Amazon Cli S3

if you look in the main page of the cli there are two kinds of command for s3
s3 and s3api

  • s3 is very simple and with few commands
  • s3api have a lot more options

some commands

#list all the buckets in json mode
aws s3api list-buckets 

#list all the buckets in text mode
aws s3api list-buckets --output text

aws s3api get-bucket-location --bucket mybucketname --output text

a script to list all the bucket and their region


for line in $( aws s3api list-buckets | jq ".Buckets[].Name" ); do
        BNAME=`echo $line | cut -f 2 -d '"'`
        REGION=`aws s3api get-bucket-location --bucket $BNAME --output text`
        echo $BNAME " -  " $REGION    

to use this script you need to install the jq utility first
sudo apt-get install jq

move files

aws s3 mv testaa/555.txt s3://archive-files/testaa/555.txt

list files
aws s3 ls s3://archive-files
                           PRE /
                           PRE dir1/
                           PRE dir2/

total size of one bucket in MB , from the article

aws s3 ls s3://buckename/ --recursive | awk 'BEGIN {total=0}{total+=$3}END{print total/1024/1024" MB"}'
Salvo diversa indicazione, il contenuto di questa pagina è sotto licenza Creative Commons Attribution-ShareAlike 3.0 License