5

I'm trying to connect my domain registered in Namecheap to my S3 buckets.

I've checked many questions related to this in here but my configuration seems to be ok.

I'm able to access the website through the static website endpoint provided by AWS but when I enter my custom domain in the browser, it takes a long while to load and finally says the page could not be loaded.

I waited over 48 hours and I tried cleaning my cache several times.

My boyfriend can access it in his phone but I cannot access it using any of my devices (I've even tried using my mobile data). I also asked my mom (she lives in another country) to try to access it and she cannot.

I replaced my domain name with example.com in the pictures below.

Here are my host records host records

S3 buckets: S3 buckets

"example.com" is my main bucket. "www.example.com" just redirects all the requests to the main bucket. This is the bucket policy I'm using in the main bucket:

 {
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "PublicReadGetObject",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::example.com/*"
        }
    ]
}

and the one I'm using in the secondary bucket(www.example.com)

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "PublicReadGetObject",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::www.example.com/*"
        }
    ]
}

Static website hosting configuration of the main bucket: main bucket static website hosting configuration

Static website configuration of the secondary bucket: secondary bucket static website hosting configuration

I tried pinging the domain and it returns enter image description here

When I try to access the IP address shown in the ping command, it just shows me the main S3 page.

ecrb
  • 670
  • 4
  • 17
  • In this similar [issue](https://stackoverflow.com/a/37578069/248823) they have s3 redirections opposite to you. Static website is hosted at `www.example.com`, while `example.com` is redirected to `www.example.com`. Don't know if this is the cause of your issue, but maybe worth checking it out? – Marcin Apr 19 '20 at 09:13
  • I just tried it. Still have the same problem. – ecrb Apr 19 '20 at 09:21
  • @Tecnogirl *"When I try to access the IP address shown in the ping command, it just shows me the main S3 page."* That's normal. S3 uses something called "name-based virtual hosting" that relies on the browser to identify the requested hostname, which is zero-config browser behavior and allows an essentially infinite number of sites to use exactly the same IP address. Disregard the fact that you see a page about S3 when you access it using the IP -- it isn't your bucket's IP, it's shared by many, many buckets. – Michael - sqlbot Apr 19 '20 at 13:49

1 Answers1

6

Ok, so I figured out what was wrong.

My domain ends in .dev. I didn't know but this extension is only for HTTPS. Most browsers know the list of extensions that only serve HTTPS and when you type http://example.com, they automatically redirect to https://example.com.

My boyfriend's phone browser (Samsung Internet) apparently does not redirect automatically and so it could render my website on http://.

So, to solve my issue I had to get an SSL certificate for my domain and install it on AWS.

This meant importing the certificate using ACM, then creating a CloudFront distribution that uses that certificate and points to the S3 bucket.

It now works :)

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
ecrb
  • 670
  • 4
  • 17