Skip to content

Instantly share code, notes, and snippets.

@mtrojanowski
Created March 8, 2015 11:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mtrojanowski/22fa648439934f0282cb to your computer and use it in GitHub Desktop.
Save mtrojanowski/22fa648439934f0282cb to your computer and use it in GitHub Desktop.
Simple script to count AWS DiskSpace usage
$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