Domain name setup with AWS S3 bucket with static hosting

Viewed 2609

Im trying to link my domain name to a static website on aws S3

I have 2 buckets set up on S3 one is domain.com and the other is www.domain.com. doamin.com has static website hosting enabled www.domain.com redirects to the domain.com

I can access my index page through: https://s3.us-east-2.amazonaws.com/domain.com/index.html but it doesn't work with this url and I get an access denied message: https://s3.us-east-2.amazonaws.com/domain.com

I have 2 host records both are CNAME:

Host: @ Value: www.domain.com.s3-website-us-east-2.amazonaws.com

Host:www Value: domain.com.s3-website-us-east-2.amazonaws.com.

In my browser it says "site can't be reached" when I have either of those cname values as my url. Also my domain is registered with NameCheap and I can't transfer it to route 53 as it is not old enough. I've never done this before so I really don't understand what I'm doing wrong.

3 Answers

You don't need to transfer the domain to AWS. All you need to do is create a hosted zone in AWS route 53. What you're going to do is set up a new DNS configuration inside AWS and then tell your registrar (NameCheap) to use the AWS nameservers.

  1. Create the hosted zone with your domain name, domain.com
  2. Create an A record for your domain. On the right side you'll see a radio button "Alias" choose yes, then click into the target box and wait for your bucket to appear under S3 Website endpoints. (More on this below).
  3. Select your bucket and click create.
  4. Head over to your registrar, NameCheap and configure the nameservers to use the AWS nameservers in the NS record from your AWS hosted zone.

In order for this to work you need to make sure your S3 bucket is named and configured correctly.

  1. Your bucket name must match the domain name.
  2. In the properties tab, you need to enable the static website hosting option and provide your index page.
  3. In the permissions tab, click on bucket policy, then click the policy generator link at the bottom.
  4. In the policy generator, select S3 as the type of policy
  5. Set the principal to *
  6. set the action to Get Object
  7. set the ARN to the ARN for your bucket /*. For example arn:aws:s3:::domain.com/ *
  8. Click Add statement, then generate policy and paste that into the bucket policy and save.

Finally upload your assets and you're done

Related