Cory O'Daniel – These are just words Software development, thoughts, and randomness

11Feb/100

Lower ACL Permissions on Amazon S3 items with ruby

I recently had to change a bunch of permissions on some items on S3. Unfortunately the items were mixed in with items that I didn't want to change the permissions on and the file names are all kinda jumbled, so I couldn't pinpoint what I needed to change by eyeballing the file names.

So I wrote a little ruby method to go in and change something given a key and bucket name.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
require 'aws/s3'
 
AWS::S3::Base.establish_connection!(
  :access_key_id     => "YOUR_ACCESS_KEY",
  :secret_access_key => "YOUR_SECRET_KEY"
)
 
include AWS::S3
def s3_set_public_read(key, bucket)
  puts "Processing: #{key}"  
 
  policy = S3Object.acl(key, bucket)
  policy.grants << ACL::Grant.grant(:public_read)
  policy.grants << ACL::Grant.grant(:public_read_acp)
  S3Object.acl(key, bucket, policy)      
end

Now I can just run a loop of ActiveRecord objects around that method and convert them all to public read.

If you want a GUI tool for managing S3 stuff, I totally recommend S3Hub. Its a really sexy tool for managing S3.

Post to Twitter Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

Tagged as: , , No Comments