Skip to content

Instantly share code, notes, and snippets.

@stefan-mees
Last active December 18, 2015 15:19
Show Gist options
  • Save stefan-mees/5803315 to your computer and use it in GitHub Desktop.
Save stefan-mees/5803315 to your computer and use it in GitHub Desktop.
aws s3 add expire / cache header to existing objects
AWS.config({
:access_key_id => 'xxxxx',
:secret_access_key => 'xxxxx',
})
bucket_name = 'xxxxx'
s3 = AWS::S3.new()
bucket = s3.buckets[bucket_name]
File.open('/tmp/listofkeys.txt').lines.each_with_index do |line,index|
key = line.strip
object = bucket.objects[key]
object.copy_to(key, :metadata => object.metadata.to_h, :content_type => object.content_type, :acl => :public_read, :expires=>"Thu, 31 Dec 2037 23:55:55 GMT", :cache_control=>"max-age=31556926")
p "progress: #{index}" if index%100==0
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment