Stop Serving Images Directly From s3.amazonaws.com – Alias The Domain
I see a lot of websites serve images directly from s3.amazonaws.com. Do you know a lot of corporates just blindly block this url? What your users may see is just empty “x” boxes instead of your beautiful images and will end up viewing your website as an ugly piece like this:
LeanPub.com from a corporate network
AppSumo.com from a corporate network
How to set an alias domain name or sub-domain name to Amazon S3:
Courtesy: https://carltonbale.com/how-to-alias-a-domain-name-or-sub-domain-to-amazon-s3/
Introductory Steps for new Amazon S3 Users:
First of all, obviously, you need your own domain name and your own Amazon S3 account
Secondly, you need a way to create/manage Amazon S3 buckets, so you’ll need to install a client on your PC.
I recommend using Bucket Explorer, which is a full-featured and easy-to-use client that runs on Windows and Linux; (a Mac version is in private beta and should be available Oct 2007).
A free, less-featured alternative is the S3 Organizer add-on for the Mozilla Firefox web browser.
Install your application of choice and either:
- Open Bucket Explorer -or-
- Open Firefox and go to Tools menu -> S3 organizer, and click the Manage Accounts button
- Enter your AmazonAWS Access Key and Secret Key
These are available by going to https://aws.amazon.com, mousing-over the “Your Web Services Account” in the upper right-hand corner, and selecting “AWS Access Identifiers“
How to Alias your Subdomain to an Amazon S3 Bucket:
Identify the exact domain name you want to forward to Amazon S3. S3 is not a web server, so I would not recommend forwarding your entire domain there, but rather a sub-domain. The sub-domain I’m going to use is the actual one I set up: s3.carltonbale.com
Create a new “bucket” (a.k.a. folder) by clicking the “create folder/bucket” icon. Name the bucket exactly what your sub-domain name is.
Example bucket name: s3.carltonbale.com
Note: you must use a unique bucket name; you won’t be able to create a bucket if the name is already being used by someone else.
Now comes the tricky part: modifying your DNS server settings. The procedures on how to do this vary by host and software system, but are the general steps:
- Login to your web host control panel and select “Manage DNS Server Settings” or similar
- Create a new CNAME entry for your domain. For my example of s3.carltonbale.com, the entry was:
Name: s3
Type: CNAME
Value: s3.amazonaws.com.
(If you are European users, use s3-external-3.amazonaws.com. instead) - And yes, the dot at the end of “s3.amazonaws.com.” is correct, at least for me. Look at your other entries to figure out what you should enter.
- Now comes the hardest part: waiting. It took about 2 hours for my subdomain to be recognized by AmazonAWS.
- Open the subdomain name in your browser. You should now be able to access your files through any of 3 urls:
- subdomain.domain.com (as long as the bucket name is the same as the full subdomain name, it is not necessary to specify the bucket name again at the end of the url)
- your_bucket_name.s3.amazonaws.com
- s3.amazonaws.com/your_bucket_name
Final Steps
You’ll need to set permissions on your bucket and the files within using your favorite bucket management tool. I recommend setting the bucket permission to “full control by owner” only and set the permissions of the files within the bucket to “full control by owner, read access for everyone”.
This will prevent people from being able to browse/list the files in your bucket.
If you don’t want Google (or Google Images) to index the files in your subdomain, create a file named robots.txt containing the following and copy it into your bucket:
User-agent: *
Disallow: /