Wildcard Subdomain (*.example.com) with Amazon Route53 DNS and S3

I am hosting a static website using Amazon Route53 for DNS and S3 for html files. It is working fine.

Current Setup is:

example.com.  A   ALIAS s3-website-us-east-1.amazonaws.com. 
www.example.com. CNAME www.example.com.s3-website-us-east-1.amazonaws.com

(NOTE: example.com and www.example.com are S3 buckets. My HTML files reside in example.com bucket.)

Now i want to add a wildcard subdomain like this - this i what i tried:

*.example.com. CNAME  www.example.com.s3-website-us-east-1.amazonaws.com

The idea is to have anything.example.com to resolve correctly to the website. But this does not seem to be working. So when i go to website: joker.example.com i see error message on browser:

Code: NoSuchBucket
Message: The specified bucket does not exist
BucketName: joker.example.com

The @edvinas.me answer is correct. You must create a cloudfront distribution for your bucket.

When you create the cloudfront distribution set the alternate Domain Names option to *.example.com.

Then use the cloudfront url like d3lt3rsz2leycm.cloudfront.net.

Now you can to add a wildcard subdomain like this:

*.example.com. CNAME  3lt3rsz2leycm.cloudfront.net.    

And should work.


Amazon S3 uses the host name to determine the bucket name.

— http://docs.aws.amazon.com/AmazonS3/latest/dev/VirtualHosting.html

The host name is the lowercase of the value sent by the browser in the Host: header. There's not a way to configure a bucket to respond to multiple hostnames.

There are some roundabout ways to accomplish this, depending on what you are trying to do, but it's going to require an EC2 instance running HAProxy, Varnish, Apache, or something similar, to either respond to requests for the wildcard hostnames with a redirect to rewrite the browser's address bar to the real hostname/bucket name or to munge the request headers and proxy the request to S3, which is not as inefficient as it may sound, since there aren't data transfer charges between S3 and EC2 within the same region, and the latency is low.


Your S3 Bucket is configured to only accept requests for example.com (and/or www.example.com). You cannot configure your bucket to accept or any specific sub-domains that you want to be active.

The only way you could acomplish this is by using an external service like Cloudfront http://aws.amazon.com/cloudfront/ which would proxy the requests.

Michael's (sqlbot) reply seems to go cover this in more detail.