We recently started serving our Drupal training video downloads from Amazon CloudFront, a web service for content delivery, through the Lullabot Store. Because of this change we are pleased to say that the download speeds have been drastically improved. The process of integrating CloudFront into your own Ubercart store is fairly simple. However, there is a requirement that your version of PHP is compiled with OpenSSL. If OpenSSL is not enabled you will get errors. We have posted the Ubercart CloudFront module on Drupal.org so that it can be further improved.
Amazon CloudFront is a web service for content delivery. It integrates with other Amazon Web Services to give developers and businesses an easy way to distribute content to end users with low latency, high data transfer speeds, and no commitments. Amazon CloudFront delivers your static and streaming content using a global network of edge locations. Requests for your objects are automatically routed to the nearest edge location, so content is delivered with the best possible performance. Amazon CloudFront works seamlessly with Amazon Simple Storage Service (Amazon S3) which durably stores the original, definitive versions of your files. Like other Amazon Web Services, there are no contracts or monthly commitments for using Amazon CloudFront – you pay only for as much or as little content as you actually deliver through the service.
Deciding to use CloudFront
The reason we decided to consider using CloudFront was that a very small but equally important segment of our friends were having troubles downloading these large files over slower connections. At times these slower connections were not due to the type of internet connection but rather the fact that they were trying to download these files from outside of the US. We needed to find a solution and fast.
Since we were already using S3, via the Media Mover module, to serve file downloads from Ubercart it was a simple decision to at least look at the benefits of using CloudFront. Amazon's hosting and file serving services are still quite young but are rapidly growing in features and popularity. Download speeds from any location and security were at the top of our list. Each of these features have been addressed with CloudFront's current configuration.
Setting up CloudFront
Setting up CloudFront is quite simple if you already use S3. It becomes even easier if you use a desktop app like S3Hub for OSX, CloudBerry for Windows, or firefox plugin like S3 Organizer. Each application handles this slightly different, but here are the basic steps.
- Login to you S3 via the GUI app
- Right Click the folder you want to setup a CloudFront distribution
- Choose Manage Distributions
- Provide a CNAME (if desired - must create this CNAME at your domain registrar and point it to your own xxxxx.cloudfront.net provided by Amazon)
- Save & Wait for it to be created
Since S3Organizer is a plugin for Firefox it works for Windows, Mac, and Linux. Here's a good tutorial on getting this setup.
Now that CloudFront is setup it's time to configure your own Ubercart/Drupal site to access these files. Download and install the Ubercart CloudFront module then navigate to the Ubercart CloudFront settings page http://example.com/admin/store/settings/cloudfront. Here you will need to store the base URL (either the CNAME or xxxxx.cloudfront.net URL), along with paired SSH keys and KeyPairID all of which are provided by Amazon. On this page you may also set a default expire time to set how long these generated links will be valid.
That's it. From this point the module hooks into the Ubercart download link through a simple hook_file_transfer_alter(). Even if you enable this module on a live store all existing download links will still function, but they will now download the file through CloudFront. You will need to confirm that the files you are selling are currently stored in your S3 account.
Prior to setting this up we have heard from some of our friends that a 1.5GB file could take many hours. From our test on the live server we have consistently seen files this size take less than 20 minutes. This is an outstanding improvement that we now get to offer anyone who decides to checkout our excellent Drupal training videos.