Created
December 24, 2013 08:08
-
-
Save sudara/8110210 to your computer and use it in GitHub Desktop.
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
require 'aws/s3' | |
bucket_name = 'yourbucket' | |
marker = "" | |
AWS::S3::Base.establish_connection!( | |
:access_key_id => "abc", | |
:secret_access_key => "abc" | |
) | |
#create the read-only by me policy | |
owner_grant = AWS::S3::ACL::Grant.new | |
grantee = AWS::S3::ACL::Grantee.new | |
grantee.type = "CanonicalUser" | |
grantee.id = 'abc' # get this from your security page https://console.aws.amazon.com/iam/home?#security_credential | |
grantee.display_name = "your name" | |
owner_grant.grantee = grantee | |
owner_grant.permission = 'READ' | |
# Iterate over all files inside bucket and apply the policy to each files | |
loop do | |
objects = AWS::S3::Bucket.objects(bucket_name, :marker=>marker, :max_keys=>1000) | |
marker = objects.last.key | |
puts "new marker is \"#{marker}\"" | |
objects.each do |obj| | |
policy = AWS::S3::S3Object.acl(obj.key, bucket_name) | |
policy.grants = [owner_grant] | |
AWS::S3::S3Object.acl(obj.key, bucket_name, policy) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment