Skip to content

Instantly share code, notes, and snippets.

@rileydutton
Created May 20, 2011 14:00
Show Gist options
  • Save rileydutton/982938 to your computer and use it in GitHub Desktop.
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)
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