Shyamal Parikh
Shyamal Parikh

Reputation: 3068

Azure: How to add Custom Domain to Azure App through function App?

I am trying to automate adding custom domain to Azure App.

Here's what I thought of doing:

Here's what I setup in function App:

run.ps1

param($req, $TriggerMetadata)

$customDomain = $req.Query.customDomain

Set-AzWebApp `
    -Name some-app `
    -ResourceGroupName SouthEastAsia ` 
    -HostNames @($customDomain,"some-app.azurewebsites.net")

Push-OutputBinding -Name res -Value ([HttpResponseContext]@{
    StatusCode = [System.Net.HttpStatusCode]::OK
    Body = "Added Custom Domain: $customDomain"
})

function.json

{
    "bindings": [
      {
        "authLevel": "anonymous",
        "type": "httpTrigger",
        "direction": "in",
        "name": "req",
        "methods": [
          "get",
          "post"
        ]
      },
      {
        "type": "http",
        "direction": "out",
        "name": "res"
      }
    ],
    "scriptFile": "./run.ps1"
}

But this is giving me 404 NotFound error when I trigger a HTTP Get request:

https://function.domain/api/AddCustomDomain?customDomain=test

Upvotes: 0

Views: 673

Answers (1)

Bevan
Bevan

Reputation: 1424

Is there a specific reason to pass an array into the -Hostnames param? It looks like you're trying to specify the default Azure hostname but it won't be required.

Try Set-AzWebApp -Name some-app -ResourceGroupName SouthEastAsia -HostNames "$customDomain"

If you do need multiple custom domains try wrapping your var in quotes Set-AzWebApp -Name some-app -ResourceGroupName SouthEastAsia -HostNames @("$customDomain1","$customDomain2","$customDomain3")

Upvotes: 0

Related Questions