How to use System Assigned MI to access Blob Storage and Cosmos DB in Synapse Analytics

Haria, Neel 0 Reputation points
2024-12-10T16:23:43.2633333+00:00

Hi,

I am trying leverage the default system assigned managed identity a synapse workspace provides to access blob storage and cosmos db.

I have already tried the following steps which I saw in various posts:

  • Assign Role to Managed Identity:
    1. Navigate to your Blob Storage account in the Azure portal.
    2. Go to the "Access control (IAM)" section.
    3. Click on "Add" and then "Add role assignment".
    4. Assign the role of "Storage Blob Data Contributor" to the managed identity associated with your Synapse workspace.
  • Use Managed Identity in Synapse Notebook:
    • When running your Spark notebooks, enable "Run as managed identity" from the Configure session menu.
    • You can now access Blob Storage using the managed identity without needing to manage credentials manually.
  • Code snippet I am using
      
      # Install the required packages
      #!pip install azure-identity azure-storage-blob 
      
      # Import necessary libraries
      from azure.identity import ManagedIdentityCredential
      from azure.storage.blob import BlobServiceClient 
      
      # Create a managed identity credential object
      credential = ManagedIdentityCredential() 
      
      # Create a BlobServiceClient object using the managed identity credential
      blob_service_client=BlobServiceClient(account_url="https://
    
Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
5,093 questions
Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,710 questions
{count} votes

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.