S3 Says "Hello World"

Submitted by Bill St. Clair on Thu, 16 Mar 2006 02:50:48 GMT  <== Computers ==> 

I've decided to use S3 as a platform for learning Ruby. I've managed to figure out enough of the simple access control stuff to load a simple "Hello World" page accessible to the world. It's at s3.amazonaws.com/billstclair/index.html. I created it with the following (in real code, you'd check the responses for errors):

require 'S3'

# Fill in your access codes here
AWS_ACCESS_KEY_ID = 'put yours here'
AWS_SECRET_ACCESS_KEY = 'put yours here'
BUCKET = "billstclair" # Choose your own bucket. This one's mine.

# Public read access header
prh = {"x-amz-acl" => "public-read"}

# Create connection
@conn = S3::AWSAuthConnection.new(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, false)

# Create bucket with default private access
# Public access allows anyone to list all the objects with
# http://s3.amazonaws.com/BUCKET
response = @conn.create_bucket(BUCKET)

# You could change the bucket to public-read access by recreating it.
# This does NOT remove any objects in the bucket.
# response = @conn.create_bucket(BUCKET, prh)

# Create the hello world page with public-read access
response = @conn.put(BUCKET, "index.html", "Hello World", prh)

I'm going to work towards moving my 911 Timeline mirror over to S3. Should save me some bucks.

BTW, Amazon's sample Ruby S3 library is here.

Add comment Edit post Add post