234 | Chapter 7: REST, Resources, and Web Services
DELETE bucket
Deletes the specified bucket. Only the bucket’s owner may delete a bucket.
A bucket can be deleted only if it is empty; attempting to delete a nonempty
bucket will cause an error with an HTTP status code of 409 Conflict.
Object
Represents an object stored within a bucket. Accessible at the following URIs:
- http://s3.amazonaws.com/bucketkey/objectkey
- http://bucketkey.s3.amazonaws.com/objectkey
- http://bucketkey/objectkey
All object keys, as seen above, are qualified with their bucket key. An object
resource supports the following four methods:
PUT object
Stores the given data at the location specified, creating a new object or over-
writing an existing object.
GET object
Retrieves and returns the object at the specified location.
HEAD object
Returns the headers that would be returned from aGETrequest on this
object, with no body.
DELETE object
Deletes the object at the given location. By analogy to Unix file permissions,
you must have WRITE access on a bucket to delete objects within it. Delet-
ing a nonexistent object is not an error, but is effectively a no-op.
S3 Clients and Servers
Marcel Molina, Jr.’s AWS::S3 library (http://amazon.rubyforge.org/) is the most
popular client for S3. Its design was inspired by ActiveRecord, and it is simple and
elegant:
require 'aws/s3' # gem install aws-s3
AWS::S3::Base.establish_connection!(
:access_key_id => 'MyAWSAccessKeyId',
:secret_access_key => 'MyAWSSecretAccessKey'
)
image_bucket = Bucket.create "images.example.com"
S3Object.store(
'hello.jpg', # key
File.read('hello.jpg'), # value
'images.example.com', # bucket name
:content_type => 'image/jpeg',
:access => :public_read
)