Path Mapping on Route 53 domain name? - amazon-web-services

I am trying to do a path mapping on a route 53 recordset to the CloudFront instead of a domain name and i have no clue on where to locate the option or even if its possible?
I created a S3 bucket with static hosting enabled, routed it through CloudFront and mapped it to route 53.
What i didnt have trouble doing was,
www.test.com (route 53) -> xxx.cloudfront.net -> s3 bucket(origin)
But i want to be able to do this,
www.test.com/api (route 53) -> xxx.cloudfront.net -> s3 bucket(origin)
is there an option hidden somewhere i am missing to map paths?
PS: I couldn't find any related question asked on the stack, if there is please point me towards it.

Route 53 is specifically for DNS configuration, whilst it allows you to resolve hostnames to IP addresses it does not have route based routing. This would be a layer 7 feature once the hostname has been resolved.
If you want path based routing within your CloudFront distribution you have the option to create multiple behaviours specifying an origin per each behaviour. The behaviour requires you to set a path mapping that when matched will use that origin.
For more information take a look at the Can I use a single CloudFront web distribution to serve content from multiple origins using multiple behaviors? article.

Related

How to point a domain *subdirectory* (not subdomain) to AWS EC2 Instance

I have two EC2 Instances on AWS.
I can point my main domain name (sample.com)to one instance in Route 53.
but how can I point another domain (sample.com/blog) to another EC2 Instance?
For this behaviour you cannot use just Route 53 as subfolders are not part of DNS resolution.
There are many solutions you could use but the most common for a website are using either CloudFront or an ALB to use path based routing.
CloudFront
With this solution you would put CloudFront in front of your domain (Route 53 will route to a CloudFront distribution.
A forwarded location is known as an origin, therefore you would create an origin for each of the target hosts.
The routing mechanism within CloudFront would be the behaviour, with a default behaviour used to forward to your default host.
You would then create an additional behaviour based on the path pattern of the domain that you would want to be routed to the other origin (e.g. /blog*).
More information about this option is available in the Can I use a single CloudFront web distribution to serve content from multiple origins using multiple behaviors? document.
Application Load Balancer
With this option your Route 53 record would forward to an ALB.
You would create a target group for each EC2 instance, and then register this hosts within the target group.
Within the listener in the ALB you would forward all traffic by default to one fo your target groups, then add an additional rule to the listener based on path patterns to forward to the other target group when appropriate.
More information is available within the Advanced Request Routing for AWS Application Load Balancers blog post.

Cloudfront CNAME or DNS CNAME? [duplicate]

I'm totally new to Amazon and all of its services. I have set up Amazon S3 and created a CloudFront distribution but what I want is to give a custom domain name to this CloudFront distribution.
I have created a sub-domain on my server and changed the CNAME to the CloudFront distribution link but I can not access to my content on S3. Can anyone tell me full go through how I can set up with alternate domain names?
To give a custom domain name to an Amazon CloudFront distribution:
Provide an Alternate Domain Name when creating your CloudFront distribution
Create a CNAME record in Route 53 (or your own DNS provider) that points to the URL of your CloudFront distribution (eg d3i29vunzqzxrt.cloudfront.net), or create an A record in Route 53 that uses Alias = Yes and select the CloudFront distribution.
From the help tip in the CloudFront console:
If you want to use your own domain name (for example, www.example.com) instead of the CloudFront domain name (for example, d1234.cloudfront.net) for the URLs for your files, specify up to 100 CNAMEs. Separate CNAMEs with commas or put each on a new line. You also need to create a CNAME record with your DNS service to route queries for www.example.com to d1234.cloudfront.net.
Update: Since this release (Apr 8, 2019) when you add an alternate domain name to a distribution, you must also attach a SSL/TLS certificate to that distribution that covers the alternate domain name.
So, first of all make sure that after you registered the domain name with your domain provider (GoDadday, CloudFlare, Route 53 etc') and created a CNAME record
you should do the following:
Add an SSL/TLS certificate from an authorized certificate authority (for example - Let's Encrypt) to CloudFront that covers the domain name you plan to use with the distribution - to validate that you are authorized to use the domain. (Read more in here).
And only then update your distribution to add an alternate domain name:
Open Amazon CloudFront console -> General view -> Edit -> Alternate Domain Names (CNAMEs) -> enter the CNAME that you want to associate with the CloudFront distribution (for example www or home).
I think the guide is designed to have you spend more than you should. Instead, you should:
Add Alternate Domain Name as the guide says.
Create "A" record in Route 53, not CNAME. AWS will charge you for each CNAME request.

DNS CNAME & MX wildcard

I'm using all infrastructure on AWS and I need:
mydomain.com A ALIAS {S3-bucket- > } s3-website-eu-west-1.amazonaws.com.
www.mydomain.com CNAME mydomain.com
-> website on Amazon S3
*.mydomain.com CNAME {beanstalk} -> myserver-app.elasticbeanstalk.com
-> all other subdomains redirect to the Amazon Beanstalk app
*.mydomain.com MX ->
10 XXYY.in1.mandrillapp.com.
20 XXYY.in2.mandrillapp.com.
-> all emails goes to mandrillapp.
How is possible to do it?
As it's written it doesn't work because of CNAME vs. MX wildcards.
I can't use all names because subdomains will be generated dynamically.
Thank you a lot!!
David
As you have found, you can't have a CNAME and any other type of record at the same level of the DNS hierarchy. Route 53 Alias records, which you're using for your bare domain and for www were created to work around this limitation in the design of DNS, and don't have the same incompatibility issue... but the target of an Alias record can only be one of four things, at the moment: a CloudFront distribution, an Elastic Load Balancer, an S3 bucket of the same name as the hostname in the A record, or another record of the same type in the same hosted zone.
The last two won't help you, but either of the first two could.
If your beanstalk application already has an ELB, you can find that name under Load Balancers in the EC2 console, and you should be able to just use that as your Alias target for the * wildcard A-record Alias for your domain. Or, you could add a load balancer to your beanstalk app, for this purpose.
Alternately, you can create a CloudFront distribution, and configure myapp.elasticbeanstalk.com as the "custom origin" server for the distribition. Configure what CloudFront calls an "alternate domain name (CNAME)" in the distribution for *.example.com -- and, incidentally, disregard the fact that the CloudFront console calls it a "CNAME." They can also be used as Alias targets. Configure the distribution to forward the incoming Host: header to the origin, as well as any other headers you want to forward. Then, you should be able to create your wildcard Alias A record, pointing to the CloudFront distribution, which will forward requests to the beanstalk app.
The problem you're having is an issue with the rules of DNS, which forbid a CNAME record where another record exists.
If a CNAME RR is present at a node, no other data should be
present; this ensures that the data for a canonical name and its aliases
cannot be different. This rule also insures that a cached CNAME can be
used without checking with an authoritative server for other RR types.
Is there are particular reason that you want to have a wildcard MX record? I can't see any situation where it provides a benefit, yet many where it would be a very bad idea! (particularly it makes any host on the network a viable target to send spam from, as any host on that can resolve to the domain has permission to send.
If you explicitly name your MX records you can have a CNAME wildcard (actually I might need to check that! but I do believe so)

Route53 aws: GEO routing with custom path CloudFront

I have to configure a DNS table to route traffic in different paths of a CloudFront distribution.
example:
www.mydomain.com, policy geo ITALY, CNAME d1111111.cloudfront.net/IT/index.html
www.mydomain.com, policy geo IRELAND, CNAME d1111111.cloudfront.net/IE/index.html
Route 53 does not consider /it/index.html.
Other solutions?
A path is relevant to the HTTP protocol. DNS is a separate protocol and is only concerned with DNS to IP conversions.
The use of geo routing is not entirely correct in this case. GEO routing is intended to route a client to the closest datacenter, not present different content. This already happens with cloudfront anyway.
Instead you should handle this within your by either doing an IP lookup or using the browser locale. Sometimes the detection is wrong and a user should have the ability to manually change the auto detection. If the user changes thier locale, it should persist for the entire session.

CloudFront distribution not showing as Route53 alias target

I’m trying to add a route 53 record set that points to my cloudfront distribution. However, when I select ‘create record set’ in route 53 and click the alias target in the subsequent panel, the cloud front distribution is not listed. All I get is ‘No targets available’. My Distribution has been created and is enabled (and is working). I have added a CName to my distribution with the same domain name that I’m setting up in Route53, but it still doesn’t show.
How do I get my distribution to show in the Alias Target field so that I can point a Route53 ‘a’ record to it?
Thanks
Combining several correct but incomplete answers:
Only A records and AAAA are supported. Not CNAME records.
The Route53 "Alias Target" box matches against CloudFront distributions' "Alternate Domain Names" field. If you're creating a new record set for something.example.com, you should have already set the alternate domain name for one of your distributions to something.example.com.
The Route53 Management Console can be slow, and it might not find your distribution right away — wait until the distribution status is Deployed.
Make sure you have set one or more Alternate Domain Names for you distribution, otherwise it won't be listed on the target combo for Route53 Alias.
As far as I understand, that's the same as configuring ServerAlias on your Apache's VirtualHost (or the correspondent for Nginx and so on). Without it, your requests wouldn't be identified as destined to that distribution when it gets there.
From AWS's documentation:
If you're using CloudFront to distribute your content, you can use Amazon Route 53 to route queries to your CloudFront distribution. The name of your Amazon Route 53 hosted zone (such as example.com) must match an alternate domain name in the CloudFront distribution. You cannot route queries to the CloudFront domain name for your distribution (such as d111111abcdef8.cloudfront.net). The following procedure assumes that you have already registered the applicable domain names.
Make sure it's an A record rather than a CNAME record (weird, I know). I found that buried in the documentation here:
http://docs.aws.amazon.com/Route53/latest/DeveloperGuide/resource-record-sets-values-alias.html
If your distribution does not show as an alias target, you can always manually copy and paste the d123.cloudfront.net (replace d123.cloudfront.net with the actual DNS name of your distribution) in to the target. This will allow you to create the alias record.
Make sure your CloudFront distribution includes the name of your site (example.com )!
I was having the same issue and spent well over an hour trying to solve the problem...
TL/DR
Set your Origin ID in the origin in your Cloudfront Distribution to be the same as the domain name you are trying to create an alias for
More Detail
I struggled with this for some time.
In the end I compared a working CloudFront distribution which did show up in Route 53 with one that did not.
What I noticed was that the Origin Id specified in the origin for the distribution was not the domain name for my site.
This option is found in: CloudFront Distributions > [Id of distribution] > Origins and Origin Groups > Origins.
I only had one origin listed where the path was the name of a public s3 bucket. This entry also had an Origin ID field. When I updated this to be my domain name (without the www prefix) e.g. testdomain.com then I was able to see this cloud front distribution in the route 53 alias drop down.
You have to fill the Alternate Domain Names (CNAMEs) field e.g. use
www.my_site.com
*.my_site.com
For SSL Certificate field select
Custom SSL Certificate (example.com)
for this you will have to create and verify your domain with ACM, ACM has to be created in Virginia.
After that you will be able to see the Cloudfront in R53.
The trick was to enter the www before the domain because CloudFront matches against that alternate domain name with www or whatever subdomain you use. Type www or your subdomain and it will find the distribution.
It was taking forever for my cloudfront distribution status property to read deployed.
However inputting the cloudfront domain url into my address bar brought me to my website, aka the cloudfront domain url was live.
Feeling impatient, I copied this domain address and pasted it into the alias target field.
It worked!