Skip to content

Instantly share code, notes, and snippets.

@ntherning
Forked from Aupajo/s3stat_setup.rb
Last active December 18, 2015 11:09
Show Gist options
  • Save ntherning/5773402 to your computer and use it in GitHub Desktop.
Save ntherning/5773402 to your computer and use it in GitHub Desktop.
# You can skip these lines if you'd prefer to work with s3sh
require 'rubygems'
require 'aws/s3'
include AWS::S3
AWS::S3::DEFAULT_HOST.replace "s3-eu-west-1.amazonaws.com"
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment