How to get the url of an uploaded blob using user-assigned managed identities?

carom-9728 21 Reputation points
2022-12-08T11:46:59.747+00:00

I am running a function app that it gets triggered when an item of specific type is uploaded to a storage account, and it processes the item uploaded to it.

A function I wrote needs the url to the blob as an input.

  • Before I was passing the url as shown below, and it worked.

https://<storage-account-name>.blob.core.windows.net/<path-to-file-location>/<name-of-uploaded-file>?<sas-token>

  • Now, I want to use user-assigned managed identities to access the blob. I can successfully create the credential and service to the blob.
    • The user-assigned managed identity and the Function App have been given Storage Blob Data Contributor permissions on the storage account used.
    • What would the url I need to pass to my function should look like? If I pass only the below, it does not work.

https://<account-name>.blob.core.windows.net/<path_to_file_location>/<name_of_uploaded_file>

My question:

How should I pass the url to the uploaded item to the function, if I am using user-assigned managed identities / shouldn't need a sas token anymore?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,954 questions
Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
3,212 questions
Microsoft Security | Microsoft Entra | Microsoft Entra ID
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Andriy Bilous 11,821 Reputation points MVP Volunteer Moderator
    2022-12-08T12:47:12.453+00:00

    Hello @carom-9728

    You can use Managed Identity to link Azure Function with Azure Blob storage. You need to enabled Managed Identity in Azure Functions and give it permissions in Azure Storage Account(select the role “Storage Blob Data Contributor” for example).
    http://www.klaushaller.net/?p=1312

    After that you will be able to download file in code(.Net example):

        var myBlobUrl = " https://<account-name>.blob.core.windows.net/<path_to_file_location>/<name_of_uploaded_file>";  
        BlobClient bc = new BlobClient(new Uri(myBlobUrl), myCredentials);  
    
        log.LogInformation("**2**");  
    
        BlobDownloadResult downloadResult = await bc.DownloadContentAsync();  
        string downloadedData = downloadResult.Content.ToString();  
    

    https://learn.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/tutorial-linux-vm-access-storage


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.