3

I followed the instruction on S3 doc to host a static website there. Everything works with the domain name provided by S3. I can access "examplebucket.s3-website-us-east-1.amazonaws.com"

However, when I forward my own custom domain name, the domain name provider added a dot at the very end of my domain, then it's like I'm accessing "examplebucket.s3-website-us-east-1.amazonaws.com.", this won't work because Amazon thinks you're accessing a different address. And then give me 404 error.

Is there any workaround for this? or any place I should set up in S3?

Martin Schröder
  • 4,176
  • 7
  • 47
  • 81
Suanmeiguo
  • 1,365
  • 3
  • 17
  • 28
  • I think you might be misdiagnosing this, since a CNAME referencing a different domain than the zone where the CNAME itself is defined... always has to end with a dot. That's normal, and shouldn't break anything. – Michael - sqlbot Nov 22 '13 at 12:48
  • 1
    Also... the hostname of your web site (the one you're "forwarding") has to be *exactly* the same as the name of the bucket. The web site "example.com" can only work in a bucket called "example.com" while the web site "www.example.com" can *only* work in a bucket called "www.example.com" ... the two aren't interchangeable, and you can't successfully map a domain name to a bucket by any other name using DNS and S3 static web site hosting. Is this what you are doing? – Michael - sqlbot Nov 23 '13 at 04:52

1 Answers1

2

I know this is too late for the original question but there may be more people with the same issues (me last week).

I was having the same issue while trying to create a route in route53 with CloudFormation. I was trying to redirect my domain www.example.com to example-bucket.s3-website-eu-west-1.amazonaws.com.

It turns out you cannot redirect to an arbitrary bucket. The bucket name must be the same as the domain you're trying to alias. So if you want to redirect www.example.com, your bucket name must be www.example.com and the URL must be www.example.com.s3-website-eu-west-1.amazonaws.com.

Moreover cloudformation has a weird syntax. Cloudformation doesn't need the name of the bucket (it already knows it). It only needs the endpoint.

So instead of using something like

"AliasTarget": {
               "DNSName" : "example-bucket.s3-website-eu-west-1.amazonaws.com",
               "HostedZoneId" : "<zoneID>"
             },

you need

"AliasTarget": {
               "DNSName" : "s3-website-eu-west-1.amazonaws.com",
               "HostedZoneId" : "<zoneID>"
             },

And route53 where to redirect because the name of the route must be the same as the name of the bucket.

Related question https://stackoverflow.com/a/5048129/54256

Community
  • 1
  • 1
Gonfva
  • 1,428
  • 16
  • 28