Use Amazon S3 & Firefox To Serve Static Files

Tutorial Details
  • Difficulty: Intermediate
  • Completion Time: 30 Minutes

Hosting services have gotten a lot better in recent times, more storage, more bandwidth, cheaper prices. But there is only so far that regular hosting will go. When I first launched PSDTUTS, despite being on a great webhost with some big specs, we ran into both bandwidth and file serving problems when our tutorials (each containing dozens of heavy images) would land on Digg. And then a friend recommended I try using Amazon’s Simple Storage Service (aka S3).

It turned out to be really easy to use S3 like a giant, unlimited host, and I’ve been using it ever since for high-access, or heavy files like podcasts for FreelanceSwitch, images for blogs, and even for sending files to clients. In this tutorial I’ll show you how with just Firefox you can turn S3 into your own personal content delivery network.
It’s super simple, even I could do it!

Step 1

The first thing you are going to need is an account. So do the following:

  1. Log in to your regular Amazon.com account (or if you don’t have one, create one!)
  2. Go to Amazon.com/AWS (AWS = Amazon Web Services)
  3. Using your Amazon account, Create an AWS account by following the prompts
  4. When you’ve created your AWS account (shown below) you’ll see a list of web services that you might be interested in. Choose "Amazon Simple Storage Service"

Step 2

Now before you can do anything with S3 you have to Sign Up For This Web Service. (I know there’s a lot of signing up to do!)

You’ll need to provide a credit card so that Amazon can bill you for bandwidth, storage and processing. The rates are low, something like $.15 p/gb transferred.

Although you might be thinking that your webhost provides bandwith at a much cheaper rate, this probably isn’t really the case. For example a company like Dreamhost will offer you literally terrabytes of bandwidth for just a few dollars a month. However if you try to hit their servers quickly to make use of this bandwidth (e.g. during a Digg, or when you just sent a newsletter out about a download file), you’re unlikely to get either a quick download, or even a download at all. In my experience webhosts count on the fact that there are a lot of factors that ensure it’s highly unlikely you’ll ever use that bandwidth.

In the time I’ve used S3 – about 8 months now – I’ve hit it with some pretty large spikes of traffic. The biggest was a day when we had 150,000 visitors in a single day on a tutorial with a total of 3mb of images. So that day alone it served up 450gb of data, and didn’t even bat an eyelash. I’m sure in the scheme of things there are much bigger users too.

So it’s pretty safe, and it’s pretty cheap. Meanwhiles Amazon should really be paying me money for all this promotion :-)

Step 3

So anyway once you’ve signed up, click on the "Your Web Services Account" button and a little menu appears. This is where you control your account, check on your activity (ie. bill) and so on.

Click on "AWS Access Identifiers"

Step 4

Now you’ll get two numbers, your access key ID and your secret access key. Needless to say you want to keep these very safe!

Copy the two numbers out into a text editor so we have them on hand, because we’ll need them in a second.

Step 5

Next we’re going to need our Firefox Extension. If you’re not using Firefox … well you’re on your own :-) I know for example you can use Transmit on a Mac to log in to your S3 account. Presumably on Windows there is something similar (if anyone knows … please do leave a comment).

So we’re going to use the S3Fox extension from RJonna

Visit the website and click on the link shown in the screenshot to download S3Fox.

Step 6

Once installed, your Firefox will restart and then you’ll see that you can now access S3Fox either from the bottom right of your browser window or from the Tools menu.

So go to Tools > S3 Organiser and you should have a tab appear showing your S3Fox window. It’s really similar to an FTP program and hence super easy to use. There are a couple of differences though.

So click on Manage Accounts and create an account with your Access Key and Secret Key from earlier. Click Save.

Step 7

Once you’ve created an account you’ll get a blank area on the right hand side. The first thing you need to do is create a Bucket. A Bucket is Amazon terminology for what amounts to a folder or directory of files. Bucket names have to be unique across the service, so for example you won’t be able to create a bucket called "Test" because I’m sure that was like the first bucket name to go.

Anyhow right click on the right hand side and choose "Create Directory", this will in fact create a Bucket because we’re in the root. Once you have a bucket created you can create directories inside. You can also have as many buckets as you wish.

You’ll be prompted for a name and the extension will show you a bunch of rules about bucket names. Weirdly the extension seems to interchange the words bucket, folder and directory.

Step 8

So I created a bucket named "nettuts" and then added two directories inside called "003_S3" and "s3demo". Then I have dragged an image over to upload to S3. The image is called s3image.jpg.

Now Right-Click on the file and choose Edit ACL. Before you can access your file you’re going to need to change its permissions, and that’s what this does.

You’ll be prompted to give Read/Write/Full Control by ticking or unticking some selections. You only want to give Read access here, so tick the boxes.

(Note on a Mac the extension has a weird bug that when you click on the ‘x’ it doesn’t immediately change to a tick, but when you click Save, all of a sudden it does. It’s confusing and hopefully will get fixed, but you get used to it)

Step 9

Now once you have set permissions, Right Click again and choose Copy URL to Clipboard. The URL For my image is:

http://d2o0t5hpnwv4c1.cloudfront.net/003_S3/s3demo/s3image.jpg

As you can see the first part of the URL is the bucket name, then the domain, then the folders and finally the file name.

That’s It!

And that’s it, here’s the image that I placed on S3. Right click and view its location to see! (Actually all the images in this tutorial are on S3 :-)

Of course if you want to do all this dynamically with PHP or Ruby, that’s a whole other kettle of fish, and hopefully one we’ll cover here in future. You can also get WordPress and other app plugins that connect up to S3.

Tags: firefox
Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • http://www.daisy-avenue.com tracyseleana

    Thanks for this info..I’ve already started using it.

    But I’m having a problem…when I try embedding video into my blog posts, it doesn’t play the video..Anyone have any suggestions for embedding video located on S3 into a wordpress blog?

    Thanks

  • http://www.devolute.net devolute

    A useful post. Thanks for this, reading stuff on Amazon didn’t help me at all!

  • Pingback: NETTUTS - How to Use Amazon S3 & PHP to Dynamically Store and Manage Files with Ease

  • Pingback: Ethos Blog » Blog Archive » 30 websites to follow if you’re into web development

  • http://mdnet.imeem.com MD

    Oh thnx! That’s what I was looking for! :D

  • Tim

    SteadyOffload is another great service to consider. Rather than uploading your static content to a third-party host, it will automatically be mirrored, synchronized and delivered from globally scattered cache servers. Without any complicated setup stuff, it integrates very smoothly.

  • http://www.audiobookone.net Martin Aranovitch

    This is an excellent tutorial. I just opened up an account with the S3 service to host videos.

    I have two questions about Amazon S3:

    1) How do we / Can we embed the videos in our web pages? It seems that I can only get the direct link to where the video is hosted, not an embed code for pasting into HTML pages.

    2) Can we make the files private/hidden from being found/listed in search engines? I can’t seem to work out how to do this in Amazon S3.

    Thanks for any help and great tutorial!

  • Andrei

    Had a problem with firefox extension, but found this: “S3 Browser”.

  • http://www.windows7themes.com Windows Themes

    Thax ! Didn’t knew about S3 :D

  • Pingback: My First Impressions of Amazon S3 | Vandelay Website Design

  • http://condomunity.com Simon

    I’ve been following this tut closely, however after adding my profile (Key ID and secret access key) I can’t add folders or directories. I get something like an error: “The request signature we calculated does not match the signature you provided. Check your key and signing method.”

    I checked the keys 20 times what could be the problem here? Any help is really appreciated.

    • http://www.google.com karan

      have you solved this Simon ?

    • Dave

      Simon,

      I’m getting the same response when I try to log into my S3 account using Interarchy on a Mac. Any help would be greatly apprciated.

      Dave

  • Jim Leeds

    Honestly, this is nuts – just go to smestorage.com and sign up for their OpenS3 programme if you want to use your own S3 keys. Once you have uploaded you files you get a unique url for any file as well as being able to share it access the files from your Iphone or mobile or facebook etc – much easier…….

  • http://overstimulate.com Jesse Andrews

    Another Firefox extension to manage your S3 bucket/files is s3:// – it was just approved by mozilla at https://addons.mozilla.org/en-US/firefox/addon/6955

    I’m the creator of it and created it to do what you are describing in your article

  • http://agit-pop.com Andrew Boyd

    well, i successfully followed yr instructions all the way thru to creating permissions et al, but am stumped at the last step — copying URL to clipboard. i’m on a mac, and however many times i try to control-click (the right-click equivalent on a mac) the file, i can’t get a pop up menu. and there seems to be no other way to find or grab the URL.

    any offer of help on this front is welcome.

  • http://stateshirt.com state shirt

    Thanks for making this easy. I was having a hard time figuring this out!

  • Pingback: 30 Websites to follow if you’re into Web Development - Code Index

  • http://codingpad.maryspad.com mary

    I’ve been considering doing something like this with S3 for some of my image heavy websites, so this tutorial is super useful. Thanks!

  • b

    nice one you’ve saved my ass

  • http://manilaroadmap.com/ Manila Map

    Thanks! My map site is always going down in the last few days of the month because of my web host’s bandwidth restrictions. Now I don’t have to worry about how many users my site gets.

  • http://xicom.biz Sandeep Jain

    Hello,

    If I set read only permission on my files on S3 then how can I read them. I have some files on S3 and have set the read only permission. Now I need a function or command to read them with php script.

    Thanks

  • http://cloudberrylab.com Andy

    If you are on Windows try CloudBerry Explorer for Amazon S3. It makes managing files in S3 EASY http://cloudberrylab.com/ It supports most of the Amazon S3 and CloudFront features and It is a FREEWARE

  • Lisa

    Hello and thanks for the post. When I select “read only” and then try to embed into a site, nothing happens. When I go back to ACL I notice that my “read” permissions changed back to “x” mark again. Anything I’m doing wrong?

  • http://www.breitlingreplicawatches.net keidi

    Great way to serve static files. How can you find it.

  • Simon

    Good article.

    Also worth looking at how you can use Google App Engine as a pseudo CDN. It is even cheaper (i.e. free)

  • http://www.pierretasse.info/ pierretasse

    Your presentation is great and clear. I worked for one year on S3, EC2 and I know what I am telling. I think beginner will have some idea about how S3 worked and how easy it can be used.
    But you need to know that it cost something as you pay for bandwith

  • http://www.xicom.biz Xicom Technologies Ltd.

    Thank you for sharing this information … I’ve already started using it.

  • BechZhao

    Thank you for sharing this good information.

  • http://www.besttipstechnology.com technology

    I’ve been considering doing something like this with S3 for some of my image heavy websites, so this tutorial is super useful. Thanks!

  • Pingback: 20 Ways to Learn PHP « My Blog

  • Dave

    Simon,

    I’m getting the same response when I try to log into my S3 account using Interarchy on a Mac. Any help would be greatly appreciated.

    Dave

  • Amar

    Hi

    When i am directly uploading i am able to see the image in browser . but when i am using the Dynamically Store and Manage Files with Ease api from amazon s3 , am not able to view image it is always downloading the image when i am giving the path in browser …….

    can anyone help me regards ………!!!

    thanks

  • Pingback: 20 Ways to Learn PHP | LONGF

  • http://www.valuecoders.com/ ValueCoders

    Thanks for sharing this informative post, It is helpful for me.

  • Pingback: How to Use Amazon S3 & PHP to Dynamically Store and Manage Files with Ease - IWCn Systems Inc. Official Blog

  • http://rowend.com/ rowend

    Good info tuto.
    Thank you