User Tools

Site Tools


aws

AWS Cli Tips

Get the total size of an S3 Bucket (or path)

aws s3 ls --summarize --human-readable --recursive s3://BUCKETNAME/PATH
or
aws s3 ls s3://BUCKETNAME/PATH --recursive | awk '{total+=$3} END{print "total =",total/1024/1024," MB"}'

Get the total size of an S3 Bucket (using CloudWatch, for high volumes)

aws cloudwatch get-metric-statistics --namespace AWS/S3 \
  --start-time 2018-02-05T00:00:00 --end-time 2018-02-06T00:00:00 \
  --period 86400 --statistics Average --region eu-west-1 --metric-name BucketSizeBytes \
  --dimensions Name=BucketName,Value=BUCKETNAME Name=StorageType,Value=StandardStorage \
  | jq -r '.Datapoints[0].Average' \
  | awk '{total+=$0} END{print "total =",int(total/1024/1024)," MB"}'

Get Userdata script associated to the current EC2

curl http://169.254.169.254/latest/user-data

Get the number of EC2 instances on a region

aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId]' --region eu-west-3 --output text | wc -l

aws.txt · Last modified: 2019/03/25 15:00 by jdx