Customizing Amazon S3 URLs With CNAME

by Shabbir on May 20, 2010

In this Article the technique used for customizing S3 URL is fine but it is not the ideal method for delivery of your content using Amazon S3. Please refer How to Setup CloudFront as Content Delivery Network For S3

Go4Expert.com is showing signs of more powerful server requirement yet again and I am in process of looking for best server offers from ThePlanet but this time I have also started to move images on Amazon S3 specially article images but I wanted s3.amazonaws.com in the URLs to go but could not find any good article on the same but some information here and there and so thought I will share on how you can also go from

banner Customizing Amazon S3 URLs With CNAME

http://imgs.g4estatic.com.s3.amazonaws.com/banner.jpg

To

banner Customizing Amazon S3 URLs With CNAME

http://imgs.g4estatic.com/banner.jpg

With Amazon S3.

I assume that you have an Amazon S3 account and are aware of the process of creating buckets and uploading files to Amazon. If you are not sure of how to do it you can use S3Fox which is a very good Mozilla plug-in to manage your Amazon S3.

First create a bucket in Amazon S3 with exactly the same domain name / sub domain name. I wanted the URL to be imgs.g4estatic.com and so my bucket name in Amazon is also imgs.g4estatic.com.

Now go to your domain DNS. In my case g4estatic.com is registered at GoDaddy and so I go to DNS control for the Domain and setup a new CName for my domain i.e. imgs and target that to the bucket of Amazon s3 i.e. imgs.g4estatic.com.s3.amazonaws.com. Setting the target to s3.amazonaws.com also works but results in extra HTTP redirects.

Wait for the DNS to propagate but for new CName the change is instant. Now upload everything under the bucket and if you allow public read for the uploaded content you will be able to view your uploaded files in the browser.

Note: DNS names are case insensitive, but Amazon S3 can only have lower-case letters and so try to have everything in lower case only.

Sign up for Free Course on Ways to Make Money Online?

Don't wanna sign up but prefer posts delivered to your Inbox?

But if you are not planning to subscribe through Email. Try subscribing to RSS.

{ 34 comments… read them below or add one }

Kanasu October 13, 2012 at 10:38 am

Hi,

S3
Bucket Name – http://www.img.mydomain.com

CNAME(BigRock) :
Name – http://www.img.mydomain.com
Value – http://www.img.mydomain.com.s3-ap-southeast-1.amazonaws.com

I’ve a file in my bucket. It works in

https://s3-ap-southeast-1.amazonaws.com/www.img.mydomain.com/dummy.jpg

but not at
http://www.img.mydomain.com/dummy.jpg

It gives a 404 ” File or directory not found”

Thanks,
Kanasu

Reply

Shabbir October 13, 2012 at 11:04 am

Kanasu, CName name should not be http://www.img.mydomain.com but only img. It may vary from your DNS interface though but ideally it should be only the first part of your domain.

Reply

Kanasu October 13, 2012 at 11:20 am

I know. I’ve created two CNAMEs. One with just img and the other with http://www.img

Still, it’s not working.

Reply

Shabbir October 13, 2012 at 2:04 pm

Kanasu, can you share your exact domain because there is no reason for not working.

Reply

Ray October 10, 2012 at 10:47 pm

Hi, I am following your advice but seems could not succeed..

I want the following
http://liangpai.s3.amazonaws.com/uploadImage/shareImage/2012-10/506dc1ef71dcf.png

showing as:

http://imgs.liangpai.me/uploadImage/shareImage/2012-10/506dc1ef71dcf.png

My S3 bucket name is “liangpai”. On Route 53, I created a new CNAME named “imgs”, the value I entered for it is “liangpai.s3.amazonaws.com”

After this I don’t see http://imgs.liangpai.me/uploadImage/shareImage/2012-10/506dc1ef71dcf.png

Can you help?

Thanks!
Ray

Reply

Shabbir October 11, 2012 at 10:08 am

Ray, your bucket in Amazon S3 should be exactly the same domain name / sub domain name.

Reply

Ray October 10, 2012 at 10:43 pm
Soroush Pour March 23, 2012 at 11:06 pm

Great stuff, this was pretty annoying until I read this and figured it out, thanks Shabbir

Reply

Shabbir March 24, 2012 at 8:06 am

The pleasure is all mine Soroush

Reply

Laxmana Rao January 28, 2012 at 6:35 pm

Thanks lot mere bai it’s success now my website is live with amazon S3 with Cloudfront

do you any internet marketing idea that promot the new sites. etc email marketing, seo, backlinks

Regards
Laxmana Rao

Reply

Shabbir January 28, 2012 at 8:55 pm

Laxmana Read the following Traffic Tips.

Reply

Laxmana Rao January 28, 2012 at 4:35 pm

ok I contact my host provider they said Subdomain of CName working fine but why I accessing it. it’s not showing Flower.gif image it’s giving error below:
NoSuchBucketThe specified bucket does not existcdn.vookster.com5BAE85CCE9E1CC87FboJyJ3hGwt5mbfqDZKkGbbA7bqv2Cu8R/4CLteJ4Na1XxeRQT2zs7nmBNGT1KLZ

the url i try to access the s3 backet
http://cdn.vookster.com.s3.amazonaws.com/vookster/Flower.gif
brother what you think problem where ?

Reply

Shabbir January 28, 2012 at 5:48 pm

Your files are not access to public.

Reply

Laxmana Rao January 27, 2012 at 10:30 pm

Thanks for you repl

ok i have setup new bucket as well as cloudfront now my two url working but CName url not working what is the prolem> working urls:
http://vookster.s3.amazonaws.com/Flower.gif
http://s3.amazonaws.com/vookster/Flower.gif
Notworking Cname url is:
http://cdn.vookster.com/
http://www.cdn.vookster.com.s3.amazonaws.com/vookster/Flower.gif

I have add my Cname under my Hosting not in Name.com
look like this cdn.vookster.com 14400 IN CNAME dtgxnog5a4zcn.cloudfront.net.vookster.com. (last dot automatically add)

Reply

Shabbir January 28, 2012 at 12:34 pm

The CName answer for cloudfront should be only dtgxnog5a4zcn.cloudfront.net and nothing more.

Reply

Laxmana Rao January 28, 2012 at 2:22 pm

when add new Cname under my DNS Management that time I am not enter anything after cloudfront url after again I login to DNS manager it showing look like this dtgxnog5a4zcn.cloudfront.net.vookster.com.

Reply

Shabbir January 28, 2012 at 3:28 pm

May be WHM is doing something.

Reply

Laxmana Rao January 27, 2012 at 4:19 pm

Hellow Sir,

Iam new for Amazon S3. I did’t understanding how to setup S3 with ColudFront for my site.

I register my domain name with Name.com, they saying if you want work the DNS service you should enable our name server without that we are not able to help or ask hosting provider they said.

What have do I don’t undestand

iam using for vookster.com script phpfox i ask they also but thier side also no good response please help me to resolve this issue.

for setup S3 backet as well as cloudfront for my site.

Status : Waiting for your reply

Regards
Laxmana Rao G

Reply

Shabbir January 27, 2012 at 6:24 pm

Hi Laxmana,

Let us take one step at a time.

You have your Amazon S3 bucket setup done and so you should be able to browse through your publicly uploaded images like mine here

http://imgs.g4estatic.com.s3.amazonaws.com/banner.jpg

http://vooksterusercontent.vookster.com.vooksterusercontent.s3.amazonaws.com/banner.jpg

Once this is done you should be able to convert Amazon url to your domain url by creating the CName for

vooksterusercontent and add the answer as vooksterusercontent.vookster.com.vooksterusercontent.s3.amazonaws.com

This is all you need and I am not sure what else is required.

I have few domains in name.com and I have done the same. cdn.imtips.in is what I use here at imtips.co and it works fine in name.com

Reply

Laxmana Rao January 28, 2012 at 10:18 am

Thanks for help brother.

I have setup s3 backet again now two url i can access but CName url not configure well i think. both url is :http://vookster.s3.amazonaws.com/Flower.gif
http://s3.amazonaws.com/vookster/Flower.gif

my CName i used as cdn.vookster.com

I Added DNS CName at my hosting screen shoot http://www.chatfriendz.com/cek.jpg
but my name.com support say below issue for updating Cname at Name.com :
Original MS from NAME.com
Hello,

The DNS records can only be managed with whoever you have the Name-servers pointed to. In this case your name-servers are pointed to:

ns1.chatfriendz.com
ns2.chatfriendz.com

And therefor you would have to setup the DNS records there.

If you want to be able to manage your DNS records with us, you would have to use our name-servers. However, if you change your name-servers to our name-servers you would have to setup the DNS records from within to point to your hosting. We can assist you with this, but you would have to obtain the DNS records from your hosting provider in order for us to set them up. If you have any additional questions or concerns, certainly let us know. We would be happy to provide further assistance.

Regards,

Henrik
——————————–

Regards
Laxmana Rao Gedala

Reply

Shabbir January 28, 2012 at 12:35 pm

If name.com does not manage your DNS you should be doing it where you have it managed.

Reply

Laxmana Rao January 28, 2012 at 2:19 pm

I Managed it under my whm panel under DNS Management this is the screen shoot http://www.chatfriendz.com/cek.jpg for it

Reply

Laxmana Rao January 27, 2012 at 10:13 am

can please tell how complete setup my CDN on my site
please have look url
http://www.chatfriendz.com/untitled3.JPG

Reply

Laxmana Rao January 27, 2012 at 9:48 am

First of all Thank you very much for valuable time spend on my issue

I typed cname field Bucket in S3 as: vooksterusercontent
so url Cloud Front Generote
CNAMEs:vooksterusercontent.vookster.com
Origin Bucket: vooksterusercontent.s3.amazonaws.com

what should I use in record answer field, the both url look like this : vooksterusercontent.vookster.com.vooksterusercontent.s3.amazonaws.com

regards
Laxmana Rao

Reply

Shabbir January 27, 2012 at 9:59 am

You have made the simple things complex. CName answer should be your Origin bucket.

Reply

Laxmana Rao January 26, 2012 at 9:58 pm

hellow Shabbir!

I would like create cname for my domain for amazon s3
I registered by domain with name.com when I enter my CName showing error asking to type (Record Answer) please tell me how could I resolve this issue.

I have screen shoot for the error shows in my dns field
http://www.chatfriendz.com/untitled1.jpg

Regards
Laxmana Rao

Reply

Shabbir January 26, 2012 at 11:25 pm

Record answer should be your Amazon S3 bucket name in my case it was imgs.g4estatic.com.s3.amazonaws.com

Ideally you should be using Cloudfront for delivering your S3 data. See http://imtips.co/cloudfront-cdn-s3.html

Reply

AdrianTeoYC January 5, 2012 at 8:31 am

Thanks for this tip on aws :)

Reply

Shabbir January 5, 2012 at 9:51 am

The pleasure is all mine. :D

Reply

louie October 4, 2011 at 8:11 am

HI shabbir,
Thanks for the great post. Does this also work for zip files? I have been looking for solutions on my product delivery with amazon s3.

thanks,
louie

Reply

Shabbir October 4, 2011 at 11:12 am

Yes it is independent of the type of files.

Reply

louie October 4, 2011 at 12:34 pm

Thanks for that quick response. Do I need to use subdomain or can I just use a folder in a bucket. i.e. mydomain.com.s3.amazonaws.com/folder
Sorry to bother you so much.Thanks in advance.

Reply

Shabbir October 4, 2011 at 12:46 pm

Louie, you can use the S3 bucket but using S3 for downloading means more cost and if you can use the Cloudfront for distribution can reduce your cost considerably. See http://imtips.co/cloudfront-cdn-s3.html

Reply

Shabbir October 4, 2011 at 12:47 pm

You don’t need any sub-domains and can use Amazon URIs directly

Reply

Leave a Comment

Previous post:

Next post: