2

I have an S3 bucket called www.mybucket.com I have an A record: name = www.mybucket.com. It answers well with the index.html contained in the bucket.

Now I want to send any subdomain to that bucket.

I tried first with specific subdomains:

  • an A record ALIAS
    • name: alias.mytestbucket.com
    • alias target www.mytestbucket.com.
    • RESULT: 404, NoSuchBucket, The specified bucket does not exist
  • a CNAME record with NO alias
    • name: cname.mytestbucket.com
    • value: www.mytestbucket.com
    • RESULT: 404, NoSuchBucket, The specified bucket does not exist
  • a CNAME record with alias
    • name: cnamealias.mytestbucket.com
    • alias target: cname.mytestbucket.com. (the only option offered...)
    • RESULT: 404, NoSuchBucket, The specified bucket does not exist

no more ideas...

The final goal will be to redirect all subdomains to the bucket www.mybucket.com. But also ability to send different subdomains to different buckets will be good...

1
  • It's not likely that you should actually be trying this. It should be fine to refer to files in your S3 bucket by a single canonical URL. Jul 7 '20 at 22:42
1

I don't think it's possible. The way this works is that the client resolves www.mybucket.com to a generic S3 endpoint that serves millions of other buckets. It then sends Host HTTP header Host: www.mybucket.com. The S3 service then matches the host header www.mybucket.com to your bucket name www.mybucket.com and serves the index.html file from there. That's how it works.

Even if you make A / ALIAS / CNAME *.mybucket.com pointing to the www.mybucket.com it in the end still resolves to the generic S3 address - that's how DNS works, it doesn't care about any intermediate names.

Now if you try to access xyz.mybucket.com your browser sends Host header Host: xyz.mybucket.com -> S3 can't map it to any existing bucket -> you get NoSuchBucket error.

So no, you can't do it this way.


Possible Workaround: you can use a reverse proxy e.g. on EC2 or in Fargate container and point *.mybucket.com to this proxy hostname. The proxy will then make a backend request to S3 and serve the file to the client. The downside is that everything has to go through your proxy, sacrificing the high-availability of S3 API.

Hope that helps :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.