Archive for May, 2009

Amazon’s Simple Storage Service (S3)

This week, we close out our look at the Amazon Web Services implementation of the AppEngine Photo Application. S3 is perhaps one of the best known, most used services on AWS. Before we discuss using S3, I need to cover some basic terminology. The key words to know are bucket, object, and key. A bucket contains zero or more objects. An object is associated with one key.

Buckets have names and are associated with an AWS account. Upon creating a bucket, you also create an addressable resource on the Internet. For example, I can create a bucket named MyS3Bucket. Upon creating that resource, S3 enables a new URI at http://MyS3Bucket.s3.amazonaws.com and at http://s3.amazonaws.com/MyS3Bucket. The bucket can be public or private. A public bucket can be accessed by anyone whereas a private bucket requires a token to access any contents. The owner of the bucket as well as others the owner authorizes can access private contents.

A bucket has little use if it is empty. Buckets contain keyed collections of bytes called objects. Each object has a key. The key is a string. For example if the key is myfile.jpg, S3 makes the object accessible at

http://MyS3Bucket.s3.amazonaws.com/myfile.jpg

and at

http://s3.amazonaws.com/MyS3Bucket/myfile.jpg

From S3’s point of view, the key is just a string. That string may contain embedded forward slashes, /. This feature allows one to store objects in S3 using what appear to be paths. Let’s assume that we want to keep videos separated from photos. When adding a video object to S3, append the string video/ to the name of any videos and photo/ to the name of any photos. Doing this for the image above makes the URI for the user look like this:

http://MyS3Bucket.s3.amazonaws.com/photo/myfile.jpg

and

http://s3.amazonaws.com/MyS3Bucket/photo/myfile.jpg

S3 allows you to query against keys in the buckets and find the common prefixes before a particular delimiter, such as the forward slash /.Through this mechanism, you can effectively list the contents of a given prefix. Various tools utilize this functionality to allow one to browse S3 like any other directory based file system.

When uploading an object to S3, you indicate the Content-Type of the object. S3 remembers this information so that it can set the HTTP Content-Type header when someone later requests the object from S3.

Up next, we’ll look at how to use S3 from .NET!

Leave a comment

SimpleDB Delete

This post uses Amazon’s SimpleDB C# library. Deleting a record is really simple. Again, this is to delete an ASP.NET MembershipUser from SimpleDB. To do this, you simply pass the ItemName to a DeleteAttributesRequest(). Because that name is unique within the domain, the values will go away.

override this.DeleteUser(username, deleteAllRelatedData) =

    PhotoWebInit.InitializeAWS

    let simpleDb = PhotoWebInit.SimpleDBClient

    let delAttr = new Model.DeleteAttributesRequest()

    delAttr.DomainName <- PhotoWebInit.domainName

    delAttr.ItemName <- username

    let delResponse = simpleDb.DeleteAttributes(delAttr)

    true

Pretty easy, right?

Next week, we’ll finish this up with a post on Simple Storage Service and a zipped copy of the source code (in case you want to see everything in one place).

Leave a comment