Created
May 20, 2011 14:00
-
-
Save rileydutton/982938 to your computer and use it in GitHub Desktop.
Easy way to set cache control and public read permissions on all files in an S3 bucket (in Ruby)
This file contains hidden or 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
AWS::S3::Base.establish_connection!( | |
:access_key_id => "YOUR KEY ID", | |
:secret_access_key => "YOUR ACCESS KEY" | |
) | |
finished = false | |
lastkey = nil | |
while(!finished) | |
objects = AWS::S3::Bucket.objects('YOUR BUCKET NAME', :marker => lastkey) | |
objects.each do |object| | |
puts "Setting #{object.key}" | |
object.cache_control = 'max-age=315360000' | |
object.save({:access => :public_read}) | |
end | |
if(objects.size == 1000) | |
lastkey = objects.last.key | |
else | |
finished = true | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment