Posts

Calculate AWS S3 Bucket Size

Getting S3 Bucket Size Long story short you can use one of the following methods: aws s3api --profile PROFILE_NAME list-objects --bucket BUCKET_NAME --output json \ --query "[sum(Contents[].Size), length(Contents[])]" or some existing tool such as s3cmd du s3://bucket-name But it may be instructive to study in detail how to work with the AWS api: Listing the Buckets For getting the bucket size we need two S3 CLI commands s3 ls or s3api list-buckets and s3api list-objects we also need two related permissions: s3:ListAllMyBuckets - for seeing the bucket names s3:ListBucket - for listing the objects (this permission does not allow us to read the content) A new user without any permissions returns: petr@petr-VirtualBox:~$ aws --profile demo s3 ls An error occurred (AccessDenied) when calling the ListBuckets operation: Access Denied with the policy following IAM policy: { "Version": "2012-10-17", "Statement...
Recent posts