How can I change the Amazon S3 url from http://bucket.amazons3.com/imagepath.jpg to http://image.mydomain.com/imagepath.jpg
EDIT: Basically the whole reason for this is to hide the amazon s3 url from my users.
I was thinking about a HttpModule that would redirect the request from image.mydomain.com to bucket.amazons3.com. But that would require all requests to be handled by my servers first then forwarded.
Creating a CNAME on s3.amazonaws.com. is sufficient. There is no need to prepend the bucket name.
It sounds like you want to generate expiring links,
http://www.ioncannon.net/s3/21/creating-s3-urls-that-expire-using-php/
You can then generate these on the fly, and supply them as redirects via your application. So someone requests, http://images.mydomain.com/img123.jpg
and you generate a nice, auto-expiring s3 url, http://mydomain.s3.amazonaws.com/T154456.jpg?AWSAccessKeyId=1ESOMESPECIALIDJJAKJ6RA82&Expires=1241372284&Signature=ddfr%2BlkoSEPAL%2BGbMwlMzj6q%2BCY%3D
then you redirect the user to the auto-generated url. this way, even if the user looks at the html source they only see the url leading back to your site, but when they click the link, they are redirected to amazon so you don't have to worry about proxy-ing the request via your server and eating up un-necessary bandwidth.
The way i see it, you have two choices:
So, if user wants to see the http://image.mydomain.com/imagepath.jpg resource, you can internally request the original resource from http://bucket.amazons3.com/imagepath.jpg, save it locally and return it to the requesting user.
It does spend a lot of bandwidth, but if this is your critical requirement, this should be the way to go.
If I understand, you need to specify your domain name instead of S3. To do this, you need to write a handler which will act as a proxy to the amazon server.
But, that would actually double your bandwidth as you need to send the image to the client as well fetch the image for S3.
I am not sure is there any S3 specific way to handle this.
Below is Amazon S3 specific way taken from Amazon S3, CNAME record
To elaborate on Tez's answer, Amazon S3 provides support for mapping custom domains via Virtual Hosting of Buckets.
To make this work, the name of your bucket must be the full hostname you wish to map.
So, using the example in the original question, create an S3 bucket called
image.mydomain.com
and set up a CNAME for it:if you have control over your DNS why not setup a CNAME?
we have a cname setup pointing js.our-domain.com pointing to one of our buckets (oddly enough javascript files) we then just reference js.our-domain.com/jquery.js (for example) and away we go.
Depending upon your host, there are any number of ways to setup CNAME's - a google search reveals many