How can I use the same domain name in different AWS accounts? - amazon-web-services

I want to use the same domain name in different AWS account. The domain is hosted by AWS.
I have two accounts: Account A and Account B.
In Account A, I have created a certificate with AWS Certificate Manager to have a custom domain name like example.com.
What I want to achieve is using the same domain name in Account B. In order to do that I have created a new certificate with the same domain name in Account B and then in Route 53 I have created a new hosted zone with the same domain name. The certificate is issued via email validation for Account B.
I have created a S3 static website hosting and created CloudFront distribution with this domain name in Account B.
I have followed all the steps to create static website hosting from Use CloudFront to Serve a Static Website.
When I call the link example.com instead of navigating to the static website it gives the following error:
example.com’s server IP address could not be found.
ERR_NAME_NOT_RESOLVED
My question is what should I do to use the same domain name in different AWS accounts?

I have come up with a solution. It seems that the record set in Account B does not work and requests the address to hosted zone in Account A so creating the record set in Account A and using the CNAME of the distribution in Account B is the solution. The request goes to the record set in Account A and then it routes to the distribution in Account B.
The below diagram presents the solution:

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".

Why my custom domain not showing S3 bucket data?

I am trying to create a static website using Amazon S3 and Route 53 services. I created a bucket with my domain name only but after creating "A" record set in Route 53 hosted zone I am unable to access my data via domain name. And I updated name servers as well in hostinger (from where I purchased the domain).
I followed Example: Setting Up a Static Website Using a Custom Domain - Amazon Simple Storage Service even though I am facing the issue.
I enabled static website hosting as well and added a bucket policy which allow public to read my data.
Can you explain the resolution briefly?

Domain DNS: move from AWS to Heroku

I had a static page on aws with a custom-domain.com and everything worked fine. Then, I wanted to use that domain for another site deployed on Heroku. I neeeded to unbound the domain from aws, intuitively I just deleted the buckets from the aws console. Now I have:
404 Not Found
Code: NoSuchBucket
Message: The specified bucket does not exist
I contacted domain provider company. In their answer I identified, that the domain name uses aws DNSs, but not heroku. They also added that all the changes should be made in aws, unfortunately I do not have the buckets to work with.
What should I try to do next? I can buy another domain (it is not sufficient), but it will mean that I am defeated. I want to win, will you help me to conquer the "web bug"?
When Setting Up a Static Website Using a Custom Domain, the following configurations are made:
A bucket is created with a name name matching the domain (eg custom-domain.com)
Static Website Hosting is activated on the bucket, which provides a DNS name (eg customer-domain.s3.amazonaws.com)
A DNS entry is made in Route 53 or another DNS service that is a CNAME record pointing to the DNS name of the static website
Since your configuration was working, we can assume that all the above configurations had been made. Then, when you deleted the bucket, the domain name kept pointing to S3. With no bucket to display, S3 gave you the NoSuchBucket error.
If your intention is to point custom-domain.com to a different service (eg Heroku), you will need to modify the DNS entry for that domain name:
If your domain name is hosted by Route 53, go the the Route 53 management console, find the domain and enter a new CNAME or IP address
If your domain name is hosted elsewhere (eg GoDaddy), go to their control panel and enter a new CNAME or IP address
Bottom line: You want to change the DNS entry.

AWS: Linking static website to domain name on Route53 of different AWS account

I've been having issues in linking a static website hosted on S3 bucket in one AWS account to a custom domain name regsitered on Route53 on another AWS account. Is it not possible to do such types of linking, where the S3 bucket and the Route53 are on two different AWS accounts? If so, what could be the solution for my case!
Thanks in advance.
An A-record alias is needed at the zone apex (e.g. example.com) but not for subdomains (e.g. www.example.com, because here, you can use a CNAME instead) when hosting a site on S3, and this doesn't work across AWS accounts.
However... there's one word in your question that leads me to believe the following solution may be useful. The word is "registered."
custom domain name regsitered on Route53 on another AWS account
If the domain is registered by the Route 53 registrar under one AWS account, you can still create a Route 53 hosted zone on a different AWS account -- the one with the bucket -- and then change the authoritative nameservers in the Route 53 console in the first account. This delegates operational control to the second account.
Create a hosted zone for the domain in account 2 (the same one as the bucket). Make a note of the 4 NS records that Route 53 assigns to the hosted zone. Do not change them. Just note what they are. Configure this hosted zone with the appropriate A record alias pointing to the bucket.
Then, in account 1 (where you registered the domain) in the Route 53 console, click "Registered Domains."
Select your domain.
Choose "add/edit name servers."
Enter the values for the Route 53 name servers that were assigned by Route 53 for the new hosted zone in account 2.
Wait a few minutes.
Test.
It will probably take at least 15 minutes for this to start working (it can theoretically take 48 hours but this is very unlikely), and after this, you can remove the hosted zone from account 1. Its configuration is ignored, anyway, if you don't.
Route 53 will continue to bill account 1 for the annual registration, but will bill account 2 for the hosted zone. Neither account will be charged for the DNS queries, but account 2 will be billed $0.00 for them, since the queries are against an alias pointing to S3, and in such cases, queries are free.
This should work just fine. It doesn't matter that the Route 53 entry points to a bucket in a different account.
You should follow these directions: Example: Setting Up a Static Website Using a Custom Domain with a few changes...
Basically:
Create a bucket with a name that matches your domain name (eg images.example.com) and activate Static Website Hosting
Copy the Endpoint presented. It will look like: images.example.com.s3-website.amazonaws.com
In Route 53 (in any account), create a Hosted Zone for your domain (eg example.com)
Within the Hosted Zone, create a Record Set for images.example.com of type CNAME. Then enter the Static Website Hosting Endpoint that was copied above.
Then test the domain. For example, images.example.com/foo.jpg should return the foo.jpg file from your bucket.
It is not possible to use Alias=YES for a Static Website in a different account.

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.