简体   繁体   中英

How to debug Azure Function triggered by Service Bus that uses Managed Identity

I have an azure Function triggered by Service Bus.

    [FunctionName("Func")]
    public async Task Run(

        [ServiceBusTrigger("%ServiceBusQueueName%", Connection = "SBNamespaceFQName")]

        ServiceBusReceivedMessage message,

        ServiceBusMessageActions messageActions,

        Int32 deliveryCount,

        DateTime enqueuedTimeUtc,

        DateTime expiresAtUtc,

        ILogger log)
    {
        ......
    }

The authentication to service bus is done by Managed Identity and for local debug I am using Service Principal by adding the following to Startup

        Environment.SetEnvironmentVariable("AZURE_TENANT_ID", "***");
        Environment.SetEnvironmentVariable("AZURE_CLIENT_ID", "***");
        Environment.SetEnvironmentVariable("AZURE_CLIENT_SECRET", "***");

My question is if it is possible to use my Azure User credentials for local debug instead ot Service Principal, assuming my user will get all necessary roles.

For some reason once function is failing to start once I remove from Startup the abovementioned lines even if I am logged in to Azure from Visual Studio.

Am I missing something?

***** UPDATE ******

I was able to figure out what was wrong. My azure user was missing "Azure Service Bus Data Owner" role. After the role was assigned to my uer the issue resolved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM