Domain redirection based on Geo - AWS - amazon-web-services

I have basically 2 hosted zones **.com and **.co.in. For all the incoming traffic from India , if user browses .com it should automatically redirect to co.in . How do we do this in AWS . I read this http://docs.aws.amazon.com/Route53/latest/DeveloperGuide/resource-record-sets-values-geo.html#rrsets-values-geo-location and implemented in co.in hosted zone but does not seem to work. Also I think there should be some domain redirection set up in .com but cant find where we can do in Route53
Regards
Raghav

To simplify my solution, I'm going to refer to these domains as example.com and example.co.in. Here's how I'd solve this:
S3 Bucket for example.com:
Static Website Hosting:
Redirect Requests:
Target Bucket or Domain: example.co.in
Note the region that this bucket is created in, such as us-east-1, we'll need that later
Route 53 Record Set for example.com For India:
Type: CNAME
Value: example.co.in.s3-static-website-[region].amazonaws.com
Routing Policy: Geolocation
Location: India
Set ID: India Redirect
Route 53 Record Set for example.com Not India:
You'd set your Type and Value as normal
Routing Policy: Geolocation
Location: Default
Set ID: Regular Traffic
Further Reading:
Geolocation Resource Record Sets
How Do I Redirect Requests to an S3 Bucket Hosted Website to Another Host?

Related

AWS can't specify route 53 record without subdomain for cloudfront CNAME

I decided to host my self portfolio on AWS so I done following steps.
Host it on s3 (everything OK)
Buyed domain in route53
Created A type record to point my domain to s3 (everything OK)
Generated public certificate in ACM for domains: *.mywebsite.com, mywebsite.com
Created CloudFront distribution and with following setiings
ORIGIN DOMAIN NAME: links to s3 (everything OK)
CNAMES: www.mywebsite.com, *.mywebsite.com, mywebsite.com
WIEVER PROTOCOL POLICY: redirect HTTP to HTTPS
used custom certificate made in step 4
Created another CNAME record that points *.mywebsite.com to cloudfront url
and as I am totally happy about how things works when i go on website with subdomain like:
www.mywebsite.com
foobarbaz.mywebsite.com
http://www.mywebsite.com
All of those work great redirect it to my website throught https protocol
but the issue is when I try to reach my website without subdomain like that mywebsite.com thats go through http protocol and for https I end up with ERR_CONNECTION_TIMED_OUT, so I tried adding another CNAME record for name mywebsite.com and got an following error:
Error occurred
Bad request.
(InvalidChangeBatch 400: RRSet of type CNAME with DNS name mywebsite.com. is not permitted at apex in zone mywebsite.com.)
Any ideas how to get around that issue?
I am not really into networking and configuring those type of stuff, so I would appreciate any tips if I done something wrong.
#edit:
tried adding A type record with name mywebsite.com to www.mywebsite.com and received:
(InvalidChangeBatch 400: Tried to create resource record set [name='mywebsite.com.', type='A'] but it already exists), there is already one linking to S3
You have a problem in Step 3). The apex domain points to the S3 bucket, which should point to the CloudFront distribution.
Here's how it should look like:
Route53: ACM certificate CNAME, A record => cloudfront
CloudFront: ACM certificate + alias for mywebsite.com, Origin: S3 bucket
S3 bucket: host the files
Note that only A records (and AAAA, if you want IPv6) point to CloudFront, and there is only 1 CNAME record that is used by ACM to validate the domain.
AWS's doc describes this scenario. ie-
You can't create a CNAME record at the top node of a DNS namespace, also called the zone apex (such as example.com). If you're creating a record for the apex domain to point to AWS resources, you can use an alias record instead of CNAME.
Alias Records
So, you can use an Alias record with type A instead of CNAME to get around the error you're seeing.

Configure domain on Godaddy to Amazon S3 bucket

I have the static website hosted on S3 which is displaying correctly using the Amazon s3 link.
As per Amazon docs, I created two buckets, example.io & www.example.io. The example.io has the content (files) for the website; the www.example.io bucket is redirecting to the phlo.io bucket.
I am trying to configure Godaddy Apex domain DNS settings to redirect to the S3 bucket. As an example, the domain is http://example.io & I entered the settings in Godaddy domain DNS in the following form:
Type: CNAME
Name: www
value: example.io.s3-website.eu-west-2.amazonaws.com
TTL: 1 hour
However, the website is not displaying on the link http://example.io. How do I configure the apex domain to display the static website?
You can't, sorry...
AWS do not provide an IP Address that you can add as the Apex A Record. This causes issues using S3, CloudFront, ELB, and API Gateway.
If you are using AWS Route53, you can set the Apex A Record as an "alias" to those other services in your AWS account. This is an AWS bespoke service to get around only being able to set an A Record IP Address as the Apex Address.
So you can either move your DNS to AWS, or use a www redirection service. This will provide you with an IP Address which will respond with a redirection to your www.example.io address. People often use services like wwwizer.com to do this for free: http://wwwizer.com/naked-domain-redirect
On further investigation, it turns out that GoDaddy offers http redirection in its DNS service. Here is a guide to setting up naked domain name redirection to the www sub domain: https://help.ghost.org/article/17-custom-domains-using-godaddy
Steps to follow to redirect all traffic from www.yourdomain.com to www.yours3bucket.amazonaws.com
Create a bucket with the same name as your domain name(in this case www.yourdomain.com), make it public and host it.
Go to Godaddy DNS Server and Enter a CNAME Entry with host as www, Points to as www.yours3bucket.amazonaws.com and TTL as default.
(This is to redirect all the traffic to your AWS S3 Bucket, It will only work with www.yourdomain.com and not with yourdomain.com if you do not set a forwarding as mentioned on step 3)
Now also add a 301 forwarding to http://www.yourdomain.com or https://www.yourdomain.com.
(This is to forward yourdomain.com to www.yourdomain.com)

Routing traffic from AWS Route53 to AWS Cloudfront

Problem -
custom domain in CloudFront is not working
I'm hosting a static website in AWS. There is two S3 buckets - mydomain.com and www.mydomain.com, where the later one redirects to the first one.
In Route 53, mydomain.com points to S3 bucket as A record and wwww.mydomain.com act as an A record alias to mydomain.com.
Now I wanted to use CloudFront but wanted to be used as https://cdn.mydomain.com/asset/some-image.png. So, I added mydomain.com, www.mydomain.com, cdn.mydomain.com as Alternate Domain Names (CNAME) in CloudFront. But please note that I do not have a S3 bucket named cdn.mydomain.com
Now as required, in AWS ACM, I have also added mydomain.com as domain name and the other two (www and cdn) as alternate domain names and all of these 3 domain have CNAME records in AWS Route 53.
Finally, I wanted to route traffic from Route 53 to Cloudfront but wanted to use my desired cdn.mydomain.com instead. So, I have created A and AAA alias record in Route 53.
name - cdn
alias - Yes
alias target - cloudfront generated domain
Result :
cloudfront generated domain works and it points to my website but cdn.mydomain.com does not (IP address not found). Just at this point, I have created another S3 bucket cdn.mydomain.com and redirected to mydomain.com. But this action requires an A record to be added in Route 53. But there is already an A record for the same name - cdn.mydomain.com that points to CloudFront domain, so no way to create another alias for the same name.
If its clear what my problem is, then please suggest the solution for it.
Well, apparently the problem was having HTTPS only policy in CloudFront -> Viewer Protocol Policy. Don't know why it matters. Changing it to Redirect HTTP to HTTPS surprisingly solves this problem.

Alias www.example.com to the same example.com on AWS

I have an EC2 instance and i have setup a domain with route53 and an elastic IP so that my domain is poiting to the same address all the time. However, I have a problem because only https://example.com is working but not https://www.example.com. I know there must be a way to route or to create an alias so that www.example.com redirects me to example.com, but i'm not sure how to do it.
To create alias record for what's called naked Domain. You need to set A record to directly the IP address.
Go to Route53,
Create Record Set
Name: www.example.com
Type: A - IPv4 address
Alias: No
Alias Target: x.x.x.x (<-- your IP address for example.com)
AWS Documentation » Amazon Route 53 » Developer Guide » Configuring Amazon Route 53 as Your DNS Service » Working with Resource Record Sets » Supported DNS Record Types
Route53にNaked Domainを設定する方法〜ELBを利用しない場合〜(How to configure Naked Domain for Route53 ~ (without ELB))
If you want to redirect requests for www.example.com to example.com, you could use S3 Static Website Hosting, and the Redirect Requests option.
In this case, you would create a bucket named www.example.com, and in the Properties for the bucket, enable Static Website Hosting, then select Redirect Requests, and set the Target Bucket or Domain to www.example.com. Be sure to record the Endpoint URL. For example, if you created your bucket in us-west-2 the endpoint would be www.example.com.static-website-us-west-2.amazonaws.com.
Next in Route53, Open the zone for example.com, and create a Record Set. In the Name field, enter www (this field should be followed by example.com), set the Type to CNAME - Canonical Name and Alias to No. Next in the Value field, enter in the Endpoint you recorded from the Static Website Hosting section above. Again, if the domain was www.example.com and hosted in us-west-2, this should be www.example.com.static-website-us-west-2.amazonaws.com.

For S3 site, how to configure S3, Route53, and Cloudfront to always use the root domain

Using Route53, how can I configure a Cloudfront enabled S3 site to always use a root/naked domain?
Take for example, well, a domain called example.com. First, I know one needs to create two buckets, www.example.com and example.com. Beyond this, it gets tricky when using Cloudfront and Route53.
Figured this out:
S3
Put the contents of your site in bucket example.com. Note the Endpoint URL. In my case, it's something like example.com.s3-website-us-east-1.amazonaws.com.
In Properties for example.com bucket, set 'Enable web hosting'
In properties for www.example.com bucket, set 'Redirect all requests to another host name' and Redirect all requests to set to example.com
CloudFront
Create a CloudFront distribution with origin: example.com.s3-website-us-east-1.amazonaws.com (note, when using CloudFront, the default origin options in the picklist appeared as example.com.s3.amazonaws.com, but it should be example.com.s3-website-us-east-1.amazonaws.com. The former is US Standard which is US east and should work, but I ran into issues).
Route53
For example.com hosted zone, create two DNS records (should already have an NS and SOA record if zone for example is on Route53):
1
Type: A
Name: (blank) - (therefore root/naked domain, example.com)
Alias: Yes
Alias Target: 'some cloudfront id'.cloudfront.net.
2
Type: CNAME
Name: www (therefore www.example.com)
Alias: No
Value: example.com.s3-website-us-east-1.amazonaws.com