Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Rake task to set all S3 files public_read

// If you ever need to make sure all your Amazon S3 files are set to public_read, here's a rake task

   1  
   2  
   3  namespace :s3 do
   4    desc "Make all objects in S3 public_read"
   5    task :make_public_readable do
   6      require 'aws/s3'
   7      # you might have this setup as env vars, doesn't work for me as i have more than one AWS account
   8      AWS::S3::Base.establish_connection!(:access_key_id => '',:secret_access_key => '')    
   9      
  10      marker = ""
  11      
  12      loop do
  13        objects = AWS::S3::Bucket.objects('your_bucket', :marker=>marker, :max_keys=>100)
  14        puts "found #{objects.size} objects"
  15      
  16        break if objects.size == 0
  17      
  18        marker = objects.last.key
  19        puts "new marker is \"#{marker}\""
  20      
  21        public_grant = AWS::S3::ACL::Grant.grant :public_read
  22    
  23        objects.each do |o|
  24          if not o.acl.grants.include? public_grant
  25            puts "\"#{o.key}\" does not include public_read"
  26            o.acl.grants << public_grant
  27            o.acl(o.acl)
  28          end
  29        end
  30      end
  31    end
  32    
  33  end
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS