Handling WordPress media files on EC2/S3 with auto scaling

I’m working on a WordPress deployment configuration on Amazon AWS. I have WordPress running on Apache on an Ubuntu EC2 instance. I’m using W3 Total Cache for caching and to serve user-uploaded media files from an S3 bucket. A load balancer distributes traffic to two EC2 instances with auto scaling to handle heavy loads.

The problem is that user-uploaded media files are stored locally in wp-content/uploads/ and then synced to the S3 bucket. This means that the media files are inconsistent between EC2 instances.

Read More

Here are the approaches I’m considering:

  1. Use a WordPress plugin to upload the media files directly to S3 without storing them locally. The problem is that the only plugins I’ve found (this and this) are buggy and poorly maintained. I’d rather not spend hours fixing one of these myself. It’s also not clear whether they integrate cleanly with W3 Total Cache (which I also want to use for its other caching tools).
  2. Have a master instance where users access the admin interface and upload media files. All media files would be stored locally on this instance (and synced to S3 via W3 Total Cache). Auto scaling would deploy slave instances with no local file storage.
  3. Make all EC2 instances identical and point wp-content/uploads/ to a separate EBS volume. All instances would share media files.
  4. Use rsync to copy media files between running EC2 instances.

Is there a clear winner? Are there other approaches I should think about?

Related posts

Leave a Reply

1 comment

  1. You might consider looking at something like s3fs (http://code.google.com/p/s3fs/). This allow you to mount your S3 bucket as a volume on your server instances. You could simply have the code to mount the volume executed on instance start-up.

    s3fs also has the ability to use local (ephermal) directories as a cache to the s3fs directory so as to improve performance.