Created
September 2, 2009 16:25
-
-
Save tekwiz/179805 to your computer and use it in GitHub Desktop.
Ruby Snippets for 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
require 'rubygems' | |
require 'aws/s3' | |
require 'activesupport' | |
S3_KEY_ID = '' | |
S3_ACCESS_KEY = '' | |
BUCKET = '' | |
# Connect | |
AWS::S3::Base.establish_connection!( | |
:access_key_id => S3_KEY_ID, | |
:secret_access_key => S3_ACCESS_KEY | |
) | |
# List All Buckets | |
puts 'S3 Buckets' | |
AWS::S3::Service.buckets.each {|b| puts " * #{b.name}"} | |
# List All Objects in a Bucket | |
puts "S3 #{BUCKET}" | |
bucket = AWS::S3::Bucket.find(BUCKET) | |
begin | |
opts ||= {} | |
bucket.objects(opts).each {|o| puts " * #{o.key}" } | |
opts = {:marker => bucket.objects.last.key} | |
end while(AWS::S3::Service.response.parsed['is_truncated']) | |
# Turn On HTTP Debugging | |
module AWS | |
module S3 | |
class Connection | |
private | |
def create_connection | |
http = http_class.new(options[:server], options[:port]) | |
http.use_ssl = !options[:use_ssl].nil? || options[:port] == 443 | |
http.verify_mode = OpenSSL::SSL::VERIFY_NONE | |
http.set_debug_output $stderr | |
http | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment