Using Managed Identities in my Azure Function and it fails trying to convert the URI for Blob Container

Bernard Brown 75 Reputation points
2024-08-10T22:04:04.3766667+00:00

I'm using Managed Identities in Azure. My function is trying to write a file to a container. As I try to get a BlobServiceClient, it fails on creating a new Uri. Per the directions, here is my line of code:

new BlobServiceClient(new Uri(endPoint), new DefaultAzureCredential())

Here is my storage container endpoint: https://mystorageacctname.blob.core.windows.net/

Can someone let me know what I'm doing wrong here?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,911 questions
Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
3,192 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Abiola Akinbade 29,405 Reputation points Volunteer Moderator
    2024-08-11T02:29:30.9466667+00:00

    Hello Bernard Brown,

    Thanks for your question.

    I will recommend you verify that the managed identity has the necessary permissions on the storage account (e.g., "Storage Blob Data Contributor" role).

    You can mark it 'Accept Answer' and 'Upvote' if this helped you

    Regards,

    Abiola


  2. TP 124.9K Reputation points Volunteer Moderator
    2024-08-11T11:46:35.2+00:00

    Hi,

    What exception are you getting?

    using Azure.Storage.Blobs;
    using Azure.Storage.Blobs.Models;
    using System;
    using System.IO;
    using Azure.Identity;
    
    string endPoint = "https://mystorageacctname.blob.core.windows.net/";
    
    var blobServiceClient = new BlobServiceClient(
            new Uri(endPoint),
            new DefaultAzureCredential());
    
    
    

    Please click Accept Answer and upvote if the above was helpful.

    Thanks.

    -TP


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.