Last updated 17 April 2010. Created on 18 August 2009.
Edited by outmind, brianshumate, LeeHunter, anantagati. Log in to edit this page.

These instructions have been tested for cloudfront 6.x-1.1.


Ensure that your system's PHP has been compiled with curl support, or that the necessary package (e.g., php5-curl or similar, dependent on OS/distribution) is installed to provide curl support to PHP.

Install CCK and FileField/ImageField, and add an image field to some content type. Install imageapi, cloudfront, imagecache, transliteration projects. Read README.txt in cloudfront. You need an Amazon Web Services account and access to the S3 and CloudFront services. More on Amazon Web Services.

Setup a bucket on S3

S3Fox and this link were helpful.

Note that the bucket name doesn't have to be a cname ( like it would if you were serving the content off of s3. Since you are using cloudfront, the bucket name can be as simple as 'projectname'. I used 'projectname-stage' and 'projectname-prod'.

  1. Add a distribution (under 'manage distributions' in S3Fox.
  2. Record the name of the distribution ( for example)
  3. You can set up a cname to point to the distribution url, but it is not required.


Enable modules

  • CloudFront
  • ImageAPI
  • ImageAPI GD2
  • ImageCache
  • ImageCacheUI
  • Transliteration


Enable the following permissions for the administrative role

  • administer imageapi
  • administer imagecache
  • flush imagecache

Update settings.php

As per the README, update settings.php to have the AWS service keys. For more about AWS, see add to bottom of settings.php, unless $conf is already there, in which case add these keys.

$conf = array(
           'cloudfront_access_key_id' => 'access key',
           'cloudfront_secret_access_key' => 'secret access key',

Create the image preset

Go to admin/build/imagecache/add and create first imagecache preset. Use a namespace like cloudfront

Click ‘add send to cloudfront’, then add the following config params to this preset:

  • bucket name: the bucket you added above
  • distribution url: the cname or url
  • unique name: cloudfront

Go back to the user permissions directory and add the 'view imagecache cloudfront' permission to all users.

Update your theme

Again, per the README, add the following code to your template.php. Make sure you give the function an appropriate name and replace THEMENAME with your theme name.

function THEMENAME_imagecache($namespace, $path, $alt = '', $title = '', $attributes = null) {
  if (module_exists('cloudfront')) {
    return cloudview_theme_imagecache($namespace, $path, $alt, $title, $attributes);
  else {
    return theme_imagecache($namespace, $path, $alt = '', $title = '', $attributes = null);

This lets cloudfront, if enabled, rewrite the path to your image.

Add an entry to unix cron

Add the following to your unix cron file (this is not the same as cron.php):
* * * * * root wget -O /dev/null -q -t 1

You may want to run this from the command line once or twice; use this command for that:
wget -O /dev/null -q -t 1

This will push the files that have been added up to s3 and thence cloudfront.

Flush your theme cache

You modified your theme up above, and therefore need to flush the theme cache.

It's at the bottom of admin/settings/performance

Change the CCK settings to use the cloudfront url

  1. Edit the fields of the content type to which you've added an image field.
  2. Go to the 'display fields' tab.
  3. Set 'teaser' and 'full node' to 'cloudfront image' or other value as appropriate.


To test, add a content type with an image. The first time the page is viewed, it should be served from drupal/apache. The second and subsequent views, from cloudfront. The cron job you added has to run, so it may be a minute or two.

Troubleshooting tips

  1. did your uploaded image get placed under the site/default/files/imagecache/cloudfront/ directory?
  2. did your uploaded image get pushed to s3?
  3. did you clear your theme cache?
  4. is the cloudfront distribution ready?

Turning off serving from CloudFront

You may want to do this periodically, if you want to serve the images from your local server.

Go to admin/build/modules and disable cloudfront module.

To turn cloudfront back on, re-enable the module.

Looking for support? Visit the forums, or join #drupal-support in IRC.


taladega’s picture

I followed all instruction and all work perfect. Thank you.
But images are huge.
"Send to CloudFront" does not have seting options for size ie 140X80
as to Scale And Crop the content.
Or does not use other "Actions" in Preset Namespace:

Any Ideas how to solve this?

maneesh_thakur’s picture


As discussed here, I have been able to configure the module on my drupal site.
With accordance to my imagecache presets, I see my images getting loaded in s3 bucket with the help of the cron. I also have distribution url created.
Kindly , let me know if this confirms that when a user visits pages from my site, the images will be served from amazon cloudfront ?


mapreferee’s picture

How do you set up a cron job, maneesh_thakur?

I know I can set up a cron job in hostmonster. But I just dont know
why it doesnt work for me, when I add the following command in my hostmonster cron manager

* * * * * wget -O /dev/null -q -t 1

Is there something I need to do after updating the theme, in order to make it work? Or, I just miss something here.
Any help appreciated.