Call us Toll-Free:
1-800-218-1525
Live ChatEmail us

 Sponsors

How to use Amazon S3

Dawn Rossi, 10-08-2008
Amazon S3 is a great hosted storage solution, that lets you store an unlimited number of files for pennies on the dollar.

We have been using Amazon S3 for a while now as part of SoftwareProjects FileToLink.com service and wrote about the benefits of using S3 a few times in the past.

As part of this post, I will demonstrate the easiest way to put Amazon S3 to use in minutes.

Step 1: Signup

If you haven't yet signed up for an Amazon S3 account, signup here

Save your Amazon S3 access key and secret key. Those strings look something like this:


Access Key
= 0BEZAVZXSW2JMREDVZW2
Secret Key
= IR41Aa938YQgjVlUcajs6E4tq5O8sHMwerB4C9Be0

Step 2: Install S3 binary

While S3 offers API libraries for all popular programming languages, we found the easiest way to integrate S3 is to use the S3 binary. The binary is a program you can run from shell, pass arguments and have the program take care of everything with no necessary API integration in your code.

You can download S3 binary here. Install both files under your /usr/local/bin folder and chmod 755

Step 3: Setup access key as environment variable

Amazon S3 binary requires both the access key and secret key to be available as environment variables.

Open /root/.cshrc and add the two lines below:


setenv S3_ACCESS_KEY_ID 0BR2AVYHPWERMSDFSGG5
setenv S3_SECRET_ACCESS_KEY
/etc/amazon_secret_access_key.key

Replace the access key ID with yours and create a text file to hold your private key under /etc/amazon_secret_access_key.key

Tip: amazon_secret_access_key.key must be 40 characters long. Your editor may add another character as EOF. To fix that, create a simple php script that will output the string into a file, then rename that file to /etc/amazon_secret_access_key.key

Step 4: Call S3

Congratulations! You can now call the S3 binary from your code and everything will work well.

Here's how to add a single file to your S3 bucket:


  $command
= "/usr/local/bin/s3 put mybucket file.zip input.zip '$content_type'";
 
exec("$command", $arrResult);

Note the Amazon S3 binary needs the content_type passed as the last parameter.

To determine the content-type of a given file, you can use our Get Content Type function.

Mike Peters, 11-06-2008
When linking to a file on Amazon S3, always use this format:

src="https://s3.amazonaws.com/BUCKETNAME/FILENAME"

For example:

src="https://s3.amazonaws.com/media.listbuilding.com/MDTS/telemillionsupsell/player.swf"

Dawn Rossi, 04-15-2009
Great How to use Amazon S3 with Firefox post by Brett
Enjoyed this post?

Subscribe Now to receive new posts via Email as soon as they come out.

 Comments
Post your comments












Note: No link spamming! If your message contains link/s, it will NOT be published on the site before manually approved by one of our moderators.



About Us  |  Contact us  |  Privacy Policy  |  Terms & Conditions