Created
March 8, 2015 11:54
-
-
Save mtrojanowski/22fa648439934f0282cb to your computer and use it in GitHub Desktop.
Simple script to count AWS DiskSpace usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$size = 0; | |
$count = 0; | |
$keyMarker = null; | |
$params = [ | |
'Bucket' => $bucket | |
]; | |
do { | |
$params['KeyMarker'] = $keyMarker; | |
$objects = $s3client->getIterator('ListObjects', $params); | |
foreach ($objects as $row) { | |
$count++; | |
$size += $row['Size']; | |
} | |
$keyMarker = isset($row['NextMarker']) ?: null; | |
} while (isset($result['IsTruncated']) && $result['IsTruncated']); | |
echo sprintf ('%s object in bucket take up %s bytes of space.', | |
$count, | |
$bucket, | |
$size | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment