How To Use Amazon S3 With WordPress To Host Images

Amazon S3 (Simple Storage Service) is an online storage service that can be used to host static contents, like image files, instead of hosting them yourself. One of the biggest advantage of S3, is the reliability you get from Amazon servers during high traffic and their bandwidth and storage prices are low compare to other similar services. We will give you a walk through of how to integrate and configure Amazon S3 with your wordpress to host images.

Step 1) Create an Account: Having an S3 account will help :). You should know that if you already have an account with Amazon you can use it to sign up for S3. You will need Credit card or a Bank Account to sign up. Unfortunately they don’t accept PayPal. After you register your account and verify your email, you will need to create a “Secret Access Key”. Its important that you do not share your “Access Key ID” and “Secret Access Key” with anyone under any circumstances. Others can use this information to store files in you S3 account without your knowledge and cost you unwanted bills from your account.

Step 2) Create a Bucket: Amazon S3 uses “bucket” to work as folders. You need to create a bucket with a unique name. I use Firefox add-on S3Fox to access, edit and manage my buckets. You will need to edit your bucket’s ACL to let everyone have read access so that they can view static files (like images) that you will be hosting at S3.

Step 3) Create a CNAME: You should create (though not necessary) a CNAME to link your S3 bucket to a better looking subdomain instead of the usual “foo.mydomain.com.s3.amazonaws.com”, you might want to make it look like “foo.mydomain.com” (the name of the bucket). I am using Slicehost, so this is how I created a CNAME from slicemanager:

Type: CNAME
Name: foo
Data: foo.mydomain.com.s3.amazonaws.com. (yes there is a dot at the end)

Step 4) Install Amazon S3 WordPress Plugin: Amazon S3 Plugin for WordPress seamlessly integrates amazon S3 to your wordpress blog, so when you upload an image using your built in wordpress editor, it also uploads a copy to your S3 account. This plugin configuration is self-explanatory, you will need your “Access Key ID”, “Secret Access Key” and the bucket you want to use to store images.

Conclusion: Amazon S3 is a powerful storage service and this is just a small example of what you can do with it. It is important to have proper safeguards and stop direct hotlinking to static files using htaccess.