Created
December 7, 2012 02:32
-
-
Save ojimac/4230276 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
# -*- encoding: utf-8 -*- | |
require 'rubygems' | |
require 'aws/s3' | |
# コネクションを作成 | |
AWS::S3::Base.establish_connection!( | |
:access_key_id => ACCESS_KEY_ID, | |
:secret_access_key => SECRET_ACCESS_KEY | |
) | |
# 東京リージョンに設定 | |
AWS::S3::DEFAULT_HOST.replace "s3-ap-northeast-1.amazonaws.com" | |
# 一度に1000件までしか取得できないためmarkerを使って全件取得する | |
objects = [] | |
last_key = nil | |
begin | |
new_objects = AWS::S3::Bucket.objects(BUCKET_NAME, :marker => last_key) | |
objects += new_objects | |
last_key = objects.last.key | |
end while new_objects.size > 0 | |
# オブジェクトを取得 | |
objects.reverse_each do |obj| | |
if obj.key !~ /\/$/ | |
p obj | |
obj.store( | |
:cache_control => 'max-age=315576000', | |
:expires => (Time.now + 60*60*24*365*10).httpdate, | |
:access => :public_read | |
) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment