Domain name setup with AWS S3 bucket with static hosting - amazon-web-services

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.

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.
Create the hosted zone with your domain name, domain.com
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).
Select your bucket and click create.
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.
Your bucket name must match the domain name.
In the properties tab, you need to enable the static website hosting option and provide your index page.
In the permissions tab, click on bucket policy, then click the policy generator link at the bottom.
In the policy generator, select S3 as the type of policy
Set the principal to *
set the action to Get Object
set the ARN to the ARN for your bucket /*. For example arn:aws:s3:::domain.com/ *
Click Add statement, then generate policy and paste that into the bucket policy and save.
Finally upload your assets and you're done

Also my domain is registered with NameCheap and I can't transfer it to route 53 as it is not old enough.
You don't have to transfer it... the registration is locked, but the name server settings should not be... so you can use namecheap as registrar and still use Route 53 as authoritative DNS. And that is what you need to do. (You can transfer the registration to the Route 53 Registrar later, or never. Route 53 provides the two services, registrar and hosting, separately.)
Configure a new hosted zone in Route 53, configure it appropriately, and then change the authoritative nameservers at Namecheap to use the 4 nameservers that Route 53 assigned to your hosted zone.
It isn't possible to use S3 at the root (apex) of a domain that isn't hosted in a Route 53 hosted zone, because a CNAME at # is simply not a valid configuration. Some people will argue to the contrary, and some DNS providers even allow it, but it is still an entirely invalid configuration. This is why Route 53 introduced Alias A records. They are valid at the apex of a domain, and solve this issue.

Needed to have basicDNS on NameCheap and use www.domain.com as my main bucket and have domain.com redirect to the main bucket

Related

Route traffic to S3 hosted static website

Have two aws account.
Account-1 is having hosted zone abc.io
Account-2 contains the S3 bucket with static website.
How to create record set in Route53 in Account-1 so that my.abc.io routes the traffic s3 hosted website on another aws account.
You can create a DNS CNAME record in Route53 in your Account-1 for my.abc.io to a value of BucketName.s3.Region.amazonaws.com. where BucketName is your bucket name and Region is the region of the bucket.
This will let any caller redirecting DNS queries against your Route53 hosted zone towards Amazon's S3 DNS records, so this solution works on a DNS-level (not e.g. on HTTP redirect level).
Please note that a CNAME DNS record is just a textual value, that you can point to any domain name (even www.google.com). The value of a CNAME record does not need to be related to anything in your Account-1 or even anything related to an AWS resource anywhere.
Using a DNS CNAME record is just a way to tell a DNS requestor "hey, when you requested an A record for my.abc.io what you actually should be doing is requesting an A record for BucketName.s3.Region.amazonaws.com."
And AWS S3 buckets have a canonical naming scheme for their domain names.
See for further information:
https://docs.aws.amazon.com/AmazonS3/latest/userguide/WebsiteEndpoints.html#website-endpoint-dns-cname
https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html#VirtualHostingCustomURLs
You can create the HZ my.abc.io in the account with the website and create a NS record in the account with the top domain to it and set the values to the same as the NS record in the HZ in the account with the website.
After this you create all the records needed to route the traffic to your site in the account with the site. This design I think keep the accounts HZ cleaner and easier to read/follow.
I have been using this design and really need to do so due to that we not only have one account that we have connected to the "top domain account".

AWS S3 and route 53 not propagating

I purchased a domain on uniregistry (ka.beer) and I want to set it up to use S3 for hosting and using route 53 for the DNS.
Steps I have taken so far:
Create hosted zone on route 53 with the name of the root domain (ka.beer)
Taken the NS records generated from this zone and updated the NS records of the domain on uniregistry, verified that this is propagated correctly using whatismydns.net
Created 2 buckets with names ka.beer and www.ka.beer in S3
Set up the root bucket to be public using the bucket policy and uploaded a test index page
Set up both buckets for static web hosting, with the www bucket to redirect to the main domain
Created A records in route 53 for ka.beer and www.ka.beer as aliases with the alias target to be the S3 zone (s3-website.eu-west-2.amazonaws.com.)
Now what I want is when I visit www.ka.beer, for it to redirect to ka.beer and when I visit ka.beer for it to show the website uploaded to that S3 bucket and to keep the same domain name
What happens currently: www.ka.beer does not resolve and ka.beer redirects to ka.beer.s3-website.eu-west-2.amazonaws.com
Thanks
Very frustrating issue but it turns out that the nameserver records were cached on my router. Clearing local cache and using incognito did not solve the problem, I had to log in to my router and reset the cache on there and then it started resolving correctly.
It looks you were doing the AWS Example: https://docs.aws.amazon.com/AmazonS3/latest/dev/website-hosting-custom-domain-walkthrough.html
If that's the case, check your Route53 entries. The domain name should match the S3 bucket name.
ka.beer A http://ka.beer.s3-website-us-west-2.amazonaws.com
www.ka.beer A http://www.ka.beer.s3-website-us-west-2.amazonaws.com
have a look on below steps.
Login into aws console
I am assuming you have set your project on your public ip of EC2.
Go to the Route 53
Under DNS management: Click on Hosted zone
Create the new Hosted zone with specific domain(your domain)
After successful creation of hosted zone you will see NS and SOA entries with your domain name
Copy all the nameserver from here and update it under your domain DNS setting (Domain provider eg godaddy etc).
Note: Domain setting : You can visit here under your domain provider
After updating nameserver in your domain provider. It can take time for updation.
After that create A record under hosted zone under Route53 and assign the bucket or EC2 instance.
After some time your domain with point to that instance

Static website on S3 with route 53 - Site can't be reached

I have hosted a static website on S3 with suitable bucket policy set. Viewing the "endpoint" in another tab works perfectly fine. After this I created a Hosted zone in route 53 to give it a desirable human readable address.
After creating the hosted zone, I have two records in my newly created hosted zone, One being of type NS and the other being of type SOA. So far so good. I go ahead to create a new record set.
I add the name as desired, enter type as 'A' - IPv4 Address tick yes for Alias, where in the drop down (Alias Target) i can see my previously created bucket endpoint.
I set the routing policy to be simple and Evaluate Health Target set to no. The record set is created successfully. However when i enter this name in another tab, I get the "Site can't be reached". I try and test the record set using the functionality provided by AWS. Here the response code i get is "NOERROR" which i assume is a positive response. Am I missing something here.
I have also referred to this video. Am I missing something. Also, I have not created the Hosted Zones myself.
A hosted zone is not the same as domain. You have to update the NS values for your domain registrar to point to the NS values as generated by Route53.
From the docs:
When you create a hosted zone, Amazon Route 53 automatically creates a
name server (NS) record and a start of authority (SOA) record for
the zone. The NS record identifies the four name servers that you give
to your registrar or your DNS service so that DNS queries are routed
to Amazon Route 53 name servers.
[...]
After you update the settings with your domain registrar to include
the Amazon Route 53 name servers, Amazon Route 53 responds to DNS
queries for the hosted zone even if you don't have a functioning
website.
NS transfer may take from 1 to 24 hours, depending on the registrar.
I faced the same issue. I bought domain thevegfoodies.com through AWS Route 53, created simple index.html page and uploaded to bucket thevegfoodies.com and set bucket for Static website hosting ,added public policy. created second bucket www.thevegfoodies.com and redirect to thevegfoodies.com, created aliases everything , read through documents everything. But nothing worked.
Until, i realized that my redirect bucket www.thevegfoodies.com was not set for public read access. I set it too Read bucket permissions for Everyone. (Note my primary bucket thevegfoodies.com already has public access.) and i could load my website using my domain name.
Now, I have read through AWS document again just to see if I missed this step of setting up public access for redirection bucket.
https://docs.aws.amazon.com/AmazonS3/latest/dev/website-hosting-custom-domain-walkthrough.html and all other steps to setup static website.
if you check Step 2.3: Configure Your Website Redirect, it is not mention that we need to set public access.
POINT- AWS Documentation is not clear. One need to have public access to redirect bucket too.

Redirecting route53 purchased domain to s3 bucket?

I've just purchased a domain from Route 53 and created corresponding buckets in AWS s3. I've followed the instructions from: Example: Setting Up a Static Website Using a Custom Domain.
Let's say my custom domain is called customdomain.com.
I've created customdomain.com and www.customdomain.com buckets in s3 and allowed static website hosting on customdomain.com and enabled redirecting from www.customdomain.com to the customdomain.com bucket.
When I enter the endpoint for customdomain.com it works just fine, meaning my bucket policies are working correctly.
Next, in Route 53, I've set up Hosted Zone for customdomain.com.
I've also created a record set in that hosted zone with the name:
customdomain.com, type A, aliasing to customdomain.com's endpoint (which I chose from the dropdown menu). I left everything else as default then saved it. I added the record for www.customdomain.com but had it alias to customdomain.com
When I try to access customdomain.com, Chrome states that the site can't be reached.
Did I miss a step somewhere or does it take time for my site to be up due to DNS propagation or something?
Fixed it.
Apparently, the domain's name servers weren't the same as my hosted zone's name servers

Amazon Route 53 Alias not working

For some reasons I am not able to set up my static website in S3.
I am trying to resolve this from last 2 weeks but its not working for me.
What I have done is:
Uploaded files within S3 bucket.
Set up routing policy - thats fine.
Alias target dropdown - I can see the S3 endpoints.
Created Hosted zones.
Set up both the alias with and without WWW.
Result - When I am typing URL in the address bar, it throws an error..either site is down or DNS related errors.
I tried implementing the same steps 6-7 times,No problems at all but domains are not working in the end. Absolutely clueless where I am going wrong?
Your hosted zone and domain name servers could be out of sync:
In Route 53, verify the Name Servers (NS) generated by your Hosted Zone match what's listed under your Registered Domains.
SCREENSHOT: AWS Route 53 Top Left Menu - Hosted vs Registered Domains
Click on "Hosted Zones"
Select your domain (example.com)
Select the "Record Set" with type NS
Copy each line item / name server from the value box
ns1.amazon.com
ns2.amazon.org
ns3.amazon.net
ns4.amazon.co.uk
Now click on "Registered Domains"
Select your domain
Past each entry in the upper right hand corner
SCREENSHOT: Paste example.com Name Server Entries
The major steps to create an Amazon Route 53 alias to an Amazon S3 bucket are:
Create a bucket with the DNS name (eg images.my-company.com) -- note that the Bucket Name must match the DNS that you wish users to enter when accessing the URL
Activate Static Website Hosting on the Amazon S3 Bucket
In Route 53, create a Hosted Zone or use an existing Hosted Zone
Create a Record Set in the Hosted Zone
Name: Match the subdomain to the name of your S3 Bucket
Type: A
Alias: Yes
Alias Target: Select your S3 website from the pull-down list
See: Setting Up a Static Website Using a Custom Domain
The most important part is that the Bucket must have the same name as the Route 53 domain name (eg images.my-company.com).
If problems are experienced, first try to access the content via the Static Website URL. If that works, resolve the URL (eg via DNSLOOKUP or PING) and compare the IP address to a resolution of your domain name. They should both return the same IP address.
I find a solution.
It seems I deleted my hosted zone which was created by amazon first time against my domain name.
Later when i created my hosted zone again against same domain name I am supposed to update nameservers in the hosted zone page which resolved the conflict of name server resolution
In my case it was a silly Error, I was using my earlier bookmark which was using HTTPS. As soon as I used HTTP, it worked. (ps: Prior to trying this I was routing via cloud front.)
As AWS documentation,
https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/RoutingToS3Bucket.html
An S3 bucket that's configured as a website endpoint doesn't support
SSL/TLS, so you need to route traffic to the CloudFront distribution
and use the S3 bucket as the origin for the distribution.