After I learned how to use PHP to move files to S3. I was looking for a way to do this in a transparant way, so you’ll still be able to use your own domain name when storing your files on S3.
Twitter uses S3 for storing its user avatars, try loading the timeline and you’ll see the amazonaws.com url coming up in your browser status bar. While this is just a small and visual annoyance, it becomes an issue when people start linking directly to your files stored on Amazon S3. The direct link to a file on S3 will look something like http://aws.amazonaws.com/your_bucket_name/your_file_name . This is not exactly pretty and you’re missing out on a lot of Google juice. In this post I’ll show you how to avoid this in a few simple steps. Only thing you need is an S3 account and access to your DNS config file.
Open your prefered S3 access tool (I use S3Fox) and authorize it with your Amazon AWS account. You’ll find all access information on the AWS site, if you haven’t created an secret access key make one now, but remember not to give it to anybody. These keys are all you need for accessing the data on S3.
Once you’re in you need to create a new bucket in which you want to store your data. And now comes the important stuff: You will need to give this bucket the same name as you want to call your subdomain you choose for accessing the data. If you want to access your images using a subdomain like images.yourdomain.com, you’ll need to create a bucket with the name images.yourdomain.com . This will only work if your bucket has the same name as your subdomain has.
The last thing you’ll need to do now, is forward your subdomain to the amazon servers. This can be done by making a CNAME record in your DNS configuration that will point to the amazon S3 servers. How to do this depends on your hosting company, some allow you to create such an entry yourself, for others you’ll need to create a ticket. This is the entry you’ll need to create: images.yourdomain.com CNAME pointing to aws.amazon.com. (the ending dot is mandatory). If you created a bucket that’s located in Europe, you’ll need to point the subdomain to s3-external-3.amazonaws.com. instead. It will take a few hours before the subdomain will propagate, so have some patience
That’s It !
Alright you’re all set. You’ll be able to access all your files on S3 using your own subdomain. A file with a name image.jpg can be accessed using following url http://images.yourdomain.com/image.jpg .