SaaS platform generally has multiple tenants. General practice is to provide dedicated subdomain for each tenant. For eg. <tenant-name>.<domain>.com. This article describes about how it can be achieved via AWS Route 53 wildcard DNS entry.

Implementing Dynamic subdomain has several challenges

Enter the wildcard DNS record. A wildcard DNS record matches any subdomain of that domain name.

*.anshulpatel.in -> 169.254.169.254

This means any subdomain for anshulpatel.in will now resolve to 169.254.169.254. For eg:

subdomain_saas

Creating Wildcard DNS in AWS Route 53

saas_route53

Testing the Setup

For testing the setup, below python script which is based on Flask framework can be used.

Output

From the below output we can confirm that we are able to route to subdomain on-the-fly and also fetch the information regarding the subdomain.

[[email protected] ~]$ curl http://amazon.anshulpatel.in
Tenant Name:amazon
[[email protected] ~]$ curl http://facebook.anshulpatel.in
Tenant Name:facebook
[[email protected] ~]$ curl http://google.anshulpatel.in
Tenant Name:google

Reference(s)