Sha256: 8efad6fc7231c3d89024f270227233feeccd8cc790a850d33b56cc12f36bf8ee
Contents?: true
Size: 1.36 KB
Versions: 2
Compression:
Stored size: 1.36 KB
Contents
#!/usr/bin/env ruby require 'optparse' require 's3grep' require 'aws-sdk-s3' require 'csv' bucket_info = {} aws_s3_client = Aws::S3::Client.new aws_s3_client.list_buckets[:buckets].each do |bucket| name = bucket[:name] puts name bucket_location = aws_s3_client.get_bucket_location(bucket: name) aws_s3_client_region_specific = if bucket_location[:location_constraint] == '' aws_s3_client else Aws::S3::Client.new(region: bucket_location[:location_constraint]) end info = S3Grep::Directory.new("s3://#{name}/", aws_s3_client_region_specific).info bucket_info[name] = { bucket: info.bucket, creation_date: bucket[:creation_date], total_size: info.total_size, num_files: info.num_files, last_modified: info.last_modified, newest_file: info.newest_file, first_modified: info.first_modified, first_file: info.first_file } end csv_headers = { bucket: 'Bucket', creation_date: 'Creation Date', total_size: 'Total Size', num_files: 'Number of Files', last_modified: 'Last Modified', newest_file: 'Newest File', first_modified: 'First Modified', first_file: 'First File' } file = "AWS-S3-Usage-Report-#{Time.now.strftime('%Y-%m-%dT%H%M%S')}.csv" CSV.open(file, 'w') do |csv| csv << csv_headers.values bucket_info.each_value do |stats| csv << csv_headers.keys.map { |k| stats[k] } end end puts file
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
s3grep-0.1.9 | bin/s3report |
s3grep-0.1.8 | bin/s3report |