Forum Discussion
connect to Azure resources from a User Data Function
- 9 months ago
Hi mehr_sa ,
Yes, you can connect to Azure resources like Azure SQL Database and Azure Storage from a Fabric User Data Function (UDF).
Inside your UDF, you can use Managed Identity or Service Principal authentication, similar to what you do in your standalone Python script. Here’s the approach:
Enable Managed Identity for the Fabric workspace (if available in your tenant).
Grant appropriate permissions to that identity — for example:
db_datareader / db_datawriter roles on Azure SQL.
Storage Blob Data Contributor role on the storage account.
In your Python UDF, use libraries like azure-identity and azure-storage-blob or pyodbc with Azure AD authentication to connect.
Use DefaultAzureCredential() from azure.identity — it will automatically pick up the Managed Identity when running inside Fabric.
This way, you don’t have to store any credentials in code, and authentication is handled securely by Azure.
Example (conceptual):
from azure.identity import DefaultAzureCredential
from azure.storage.blob import BlobServiceClientcredential = DefaultAzureCredential()
blob_service_client = BlobServiceClient(account_url="https://<storage_account>.blob.core.windows.net", credential=credential)For Azure SQL:
import pyodbc
token = credential.get_token("https://database.windows.net/.default")
conn = pyodbc.connect("Driver={ODBC Driver 18 for SQL Server};Server=tcp:<server>.database.windows.net;Database=<db>;Encrypt=yes;TrustServerCertificate=no;", attrs_before={1256: token.token})That’s the recommended way to connect securely from a Fabric UDF.
Best regards,
Gopi Krishna
Hi mehr_sa,
Just looping back one last time to check if everything's good on your end. Let me know if you need any final support happy to assist if anything’s still open.
Thank you.