How to access Azure Service Bus using Function App identity

Question:

I am following the steps listed here, but for python code:
https://docs.microsoft.com/en-us/azure/azure-functions/functions-identity-based-connections-tutorial-2

Objective is to create a simple (hello world) function app which is triggered by Azure Service Bus message queue using identity-based connection. Function app works fine when ASB is reference via connection string, but gives this error when trying to connect via managed service identity of function app (used the specific configuration pattern __fullyQualifiedNamespace). MSI has been granted Role (Azure Service Bus Data Receiver) on ASB.

Microsoft.Azure.WebJobs.ServiceBus: Microsoft Azure WebJobs SDK ServiceBus connection string 'ServiceBusConnection__fullyQualifiedNamespace' is missing or empty.

Function code (autogenerated)

import logging
import azure.functions as func

def main(msg: func.ServiceBusMessage):
    logging.info('Python ServiceBus queue trigger processed message: %s',
                 msg.get_body().decode('utf-8'))

function.json (connection value modified based on ms docs)

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "name": "msg",
      "type": "serviceBusTrigger",
      "direction": "in",
      "queueName": "erpdemoqueue",
      "connection": "ServiceBusConnection"
    }
  ]
}

host.json (version modified based on ms docs)

{
  "version": "2.0",
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[3.3.0, 4.0.0)"
  }
}

architecture

Asked By: S2L

||

Answers:

To use a managed identity, you’ll need to add a setting that identifies the fully qualified namespace of your Service Bus instance.

For example, in your local.settings.json file for local development:

{
  "Values": {
    "<connection_name>__fullyQualifiedNamespace": "<service_bus_namespace>.servicebus.windows.net"
  }
}

Or in the application settings for your function when deployed to Azure:

<connection_name>__fullyQualifiedNamespace=<service_bus_namespace>.servicebus.windows.net

This is mentioned only briefly in the tutorial that you linked. The Microsoft.Azure.WebJobs.Extensions.ServiceBus documentation does covers this a bit better in the Managed identity authentication section.

Answered By: Jesse Squire