Aleks G
Aleks G

Reputation: 57316

Point root domain to Azure Function

In our project requirements we need to deal with a number of redirects where requests come in the form of example.com/some-uri and based on this some-uri get redirected to various places.

As all of our existing apps are already hosted in Azure (hundreds of services, databases, applications, etc, etc.), Azure Functions seem a very reasonable choice. The workload is extremely simple: match the incoming uri against a table and issue a 301 redirect to the corresponding target.

Unfortunately, with Azure Function there is no public IP address and I cannot use CNAME on the root domain (that is, I cannot use DNS syntax @ CNAME somefunction.something.azure.net)

I don't want to have to pay for an app service to just deal with these redirects. The number of requests I expect is well within the free allocation of function invocations, therefore I would be getting this essentially for free.

How can I point the root of my example.com domain to the function?

Upvotes: 7

Views: 2162

Answers (4)

mikkark
mikkark

Reputation: 135

For anyone else stumbling upon this thread, Azure Function Apps nowadays support root domains using A records even in Consumption tier. More information in the documentation: https://learn.microsoft.com/en-gb/azure/app-service/app-service-web-tutorial-custom-domain.

Edit: Turns out... it doesn't. I must have been confused by the IP Address field's tooltip in the Custom Domains tab of Function Apps, where it says "Use this IP address to configure your DNS settings for A records". Then when you click "Add custom domain" and try to add an A record it says "A records are not supported for Consumption based Function Apps."

I have used Azure Static Web Apps to host some of my websites and there is a Function App in the background as your app's API. Static Web Apps support A records so that is a way to have your Functions behind a root domain. However, Static Web Apps in free tier have limitations and the non-free tier is not pay-for-what-you-use like Consumption plan is.

Upvotes: 1

Aleks G
Aleks G

Reputation: 57316

To finish this question, the answer is, it's not possible. Naked domain record cannot be CNAME and there is no ip address for a function to create A record.

EDIT: Turns out, it is possible, but not directly. When creating Azure Functions app, you can select "Consumption plan" or "App Service plan". With App Service plan, on tiers B1 and above you do get a static IP address associated with it. Moreover, you can even use reserved IP addresses.

Upvotes: 5

Sebastien GISSINGER
Sebastien GISSINGER

Reputation: 676

I created a proxy in my azure function which maps function app root path

https://<FUNCTION_APP_NAME>.azurewebsites.net/

with my azure function ugly path

https://<FUNCTION_APP_NAME>.azurewebsites.net/api/<FUNCTION_NAME>?<WHATEVER>

You may have to play with Route template and Request override configuration in order to send your path parameter to the azure function

enter image description here

You can find Azure function public IP in Custom domain configuration

enter image description here

enter image description here

Upvotes: 0

Sebastian Achatz
Sebastian Achatz

Reputation: 678

As far as I know there is currently now way to bind your "domain root" (example.com) to an Azure Function App.

I solved that problem for me by decoupling that with a (pre-)service that manages the domain and ssl topics for me (like Cloudflare)

If you you want to stay on Azure maybe the Azure API Management is an option for you.

Upvotes: 2

Related Questions