Skip to content

Instantly share code, notes, and snippets.

@Aupajo
Created April 15, 2010 02:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Aupajo/366618 to your computer and use it in GitHub Desktop.
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
# 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 = 's3stat@s3stat.com'
# 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)
@Aupajo
Copy link
Author

Aupajo commented Apr 15, 2010

gem install aws-s3

(edit)

ruby s3stat_setup.rb

Profit follows.

@ntherning
Copy link

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