Created
April 15, 2010 02:35
-
-
Save Aupajo/366618 to your computer and use it in GitHub Desktop.
How to set up an S3Stat managed bucket using Ruby and aws-s3
This file contains 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
# You can skip these lines if you'd prefer to work with s3sh | |
require 'aws/s3' | |
include AWS::S3 | |
AWS::S3::Base.establish_connection!( | |
:access_key_id => 'abc', | |
:secret_access_key => '123' | |
) | |
# Fetch the bucket | |
bucket = Bucket.find('your-bucket-name') | |
policy = bucket.acl | |
# Enable logging | |
Bucket.enable_logging_for(bucket.name, 'target_prefix' => 'log/access_log-') | |
# Set up the logging read ACP grant | |
read_acp_grant = ACL::Grant.grant :logging_read_acp | |
# Set up the logging write grant | |
write_grant = ACL::Grant.grant :logging_write | |
# Set up the grantee | |
grantee = ACL::Grantee.new | |
grantee.email_address = '[email protected]' | |
# Set up the full control rights grant | |
full_control_grant = ACL::Grant.new | |
full_control_grant.permission = 'FULL_CONTROL' | |
full_control_grant.grantee = grantee | |
policy.grants << read_acp_grant | |
policy.grants << write_grant | |
policy.grants << full_control_grant | |
# Set the bucket's ACL | |
bucket.acl(policy) |
I had to make a small change to make this work for buckets in the eu-west-1 region. See my fork for the required changes.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
gem install aws-s3
(edit)
ruby s3stat_setup.rb
Profit follows.