Amazon Cli S3
if you look in the main page of the cli http://docs.aws.amazon.com/cli/latest/reference/index.html#cli-aws 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
#!/bin/bash
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
done
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 http://serverfault.com/questions/84815/how-can-i-get-the-size-of-an-amazon-s3-bucket
aws s3 ls s3://buckename/ --recursive | awk 'BEGIN {total=0}{total+=$3}END{print total/1024/1024" MB"}'
versione della pagina: 1, ultima modifica: 05 Jul 2016 10:39