Streaming video from Amazon S3 to a Flex application

Let's say, you want to stream videos into your RIA (Flex or Silverlight). Indeed, with that in your toolkit you can deliver crazy contextual video tutorials or build the latest youtube on steroid. Nevertheless, you should face many problems involving crossdomain security, more servers to manage, deployment issues etc... Hopefully, we have a simple solution for you.

Solution 1: the wrong way

You take care of hosting the videos file on a server behind the same domain you served your RIA application. This is important because you can't stream videos (or anything for that it matters) from another domain unless it has a liberal crossdomain.xml file in the root or unless you proxy request (a pain). Forget YouTube, Vimeo and any major video delivering solution.

Problems: all rely in the solution= "you need to take care of the files". Here come a bunch of problems: files are most of the time pretty big. You will need to back them up, you can't check them in your source control or they slow down your deploy to a new server and explode your repository size, you can, of course, host them on a separate server but, hey, it's a new server to manage etc...

Solution 2: the easy way

You can simply put your videos (and all your static files by the way) on Amazon S3. I hear your inner geek: "but Amazon S3 don't have a a liberal crossdomain.xml file!". Yes but they have virtual hosting of bucket. It means you can have a cname that points to S3 in your domain.

For example: videos.wearecloud.com can point to a S3 bucket available at videos.wearecloud.com.s3.amazonaws.com. For the Flashplayer it is exactly the same domain that served the RIA application, hence no security error. For you, it is a whole new world of easy video streaming in your RIA with nothing to worry about.

The steps

1) Create a bucket that matches the hostname you want. Let's say "videos.wearecloud.com"

2) Create a CNAME on your domain like that:

videos.wearecloud.com CNAME videos.wearecloud.com.s3.amazonaws.com

nota: the exact process depends of your DNS hosting but it should be pretty easy and, in general, involves a DNS zone file.

That's it. In your Flex app you can:

Going further

On the performance side, we are so far pretty happy with this solution. But let's face it: it is not yet as fast as with a FMS in the basement. Nevertheless, amazon annouced a few weeks ago CloudFront, that is basically a Content Delivery Network (CDN) on top of S3. An simple API call make your bucket redundant across the globe for faster delivery.

We didn't test this yet, but it should be an effective way to speed up the solution. Let us know if you test this out or if you have any trouble with the steps above.