Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

Database

Synchronize Now!


Amazon S3

The S3 web service (http://www.amazon.com/s3) costs $0.15 per month per GB of storage, and $0.20 per GB of data transferred. If you already have an Amazon account, your existing account is billed. The price is reasonable; so far I've run up a $0.03 bill. All calls to S3 go over an encrypted SSL connection (although you can use a nonSSL connection for debugging or troubleshooting). When signing up for S3, you are assigned an Access Key ID that identifies you in every S3 call. Your Access Key ID is not secret. You are also given a Secret Access Key that creates a signature that authenticates you.

S3 organizes data in "buckets" that are similar to disk folders. Although individual S3 users can have no more than 100 buckets, each bucket can hold an unlimited number of objects. Unlike disk folders, buckets cannot contain other buckets—just objects. Objects are blobs of data from 1 byte to 5 GB. Each object in a given bucket is identified by a unique key. Although my sample app only grants you access to the objects it stores, the S3 API lets you grant access to other users via access-control lists. See S3DataTransfer.AccessControlList in the sample app source code for an example of an access-control list. You can grant yourself access to an object with an access-control list containing either the e-mail address you use for your Amazon account, or your Canonical User ID. I use my Canonical User ID because my e-mail address doesn't work (because my Amazon account somehow ended up with multiple passwords). You can determine your Canonical User ID and display name by calling the ListAllMyBuckets method and inspecting the Owner.ID and Owner.DisplayName properties in the response object. That's how the Options/Settings dialog box does it.

To use S3 in a Visual Studio 2005 application, add a web reference to http://s3.amazonaws.com/doc/2006-03-01/AmazonS3.wsdl. Download the "Amazon S3 Library for SOAP" in C# from Amazon's S3 Resource Center. Add the AWSAuthConnection.cs and AWSDateConnection.cs files to your project. You'll need to add a using statement to the AWSAuthConnection.cs file that points to the web service proxy that you created when you added the web reference. See the sample app's version of AWSAuthConnection.cs for an example of this. Synchronize Files uses the AWSAuthConnection class to make all of its S3 calls because it takes care of all the security details.

Reading through the S3DataTransfer source code, you notice a few S3 API quirks. Currently the AWSAuthConnection.createBucket method always returns a null response object, even when it successfully creates the bucket. That's why S3DataTransfer.CreateBucket calls S3DataTransfer.BucketExists to determine if the bucket was created. Another quirk is that AWSAuthConnection.put stores a string, but AWSAuthConnection.get retrieves a byte array. To overcome this asymmetry, S3DataTransfer.UploadBuffer converts its byte array into a string using UTF8Encoding.GetString. When that byte array is subsequently retrieved using AWSAuthConnection.get in S3DataTransfer.DownloadBuffer, the byte array will be identical to the one previously stored.


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.