Copy S3 assets with right_aws

Lately, I’ve been using right_aws to interact with S3. One thing that I found helpful was copying assets between buckets and keeping the same permissions on them. However, it’s not as simple as just copying the assets over. You need to get the Access Control Policy from the source and put it in the copied asset.

Here’s a snippet of code that does the magic.


require 'rubygems'
require 'right_aws'

s3=RightAws::S3Interface.new(S3_KEY, S3_SECRET)
s3.copy(SOURCE_BUCKET, SOURCE_PATH, DESTINATION_BUCKET, DESTINATION_PATH, :copy, {"Cache-Control" => 'max-age=315360000', "Expires" => '315360000'})
acl_prop=s3.get_acl(SOURCE_BUCKET, SOURCE_PATH)
s3.put_acl(DESTINATION_BUCKET, DESTINATION, acl_prop[:object])

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">