Search code examples
azureazure-functionssignalrazure-resource-manager

ARM scripting ServerLess SignalR with Upstream Setting to Function App


I have a 'ServerLess' SignalR resource with an Upstream Setting to talk to a backing Function App. All is working. The problem is how to automate the creation of these resources since there appears to be a circular reference between the two.

The SignalR Upstream Setting needs the 'signalr_extension' App Key from the Function App to include in the Upstream URL template. Conversely, the Function App needs an 'AzureSignalRConnectionString' app setting. Hence the circular reference.

To complicate things, it appears that the 'signalr_extension' App Key is only created when you deploy SignalR-triggered functions to the Function App. Can a randomized App Key be set 'manually' in the Function App at ARM Template creation time instead, then used in building the SignalR resource Upstream Setting?

I've tried to 'dump' a working Function App as an output in an ARM template using listkeys/listsecrets, but the Host/App Keys do not appear to be exposed.

Is it possible to script (using ARM or Azure CLI) the creation of these resources?


Solution

  • After some experimentation, I think I've solved this. Here are the steps:

    1. in the ARM template, create the Function App and SignalR. Make the Function App depend (dependsOn) on Signal. Inject the SignalR AzureSignalRConnectionString appsetting into the Function App.

    2. Deploy the function code to the Function App.

    3. Use the Azure CLI to extract the 'signalr_extension':

      az functionapp keys list --name <function_app_name> --resource-group <resource_group>

    4. Take the resulting systemKeys/signalr_extension value and put it into another Azire CLI command:

      az signalr upstream update --name <signalr_name> --resource-group <resource_group> --template url-template="https://<function_app_name>.azurewebsites.net/runtime/webhooks/signalr?code=<code from step 3"

    At least this can all be scripted in to a DevOps pipeline.