Forum Discussion

mehr_sa's avatar
mehr_sa
Regular Visitor
9 months ago
Solved

connect to Azure resources from a User Data Function

I have a standalone Python program that performs part of ETL, which anyone can run from their local computer. I need to integrate this program into the Fabric. I found that User Data Functions are suitable for such scenarios.
In the Python program, I connect to the Azure SQL database and Azure storage account using a Service Principal or a managed Identity.
How can I connect to the Azure SQL database and Azure storage account from a Fabric User Data Function?

  • 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:

    1. Enable Managed Identity for the Fabric workspace (if available in your tenant).

    2. Grant appropriate permissions to that identity — for example:

     

4 Replies

  • 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:

    1. Enable Managed Identity for the Fabric workspace (if available in your tenant).

    2. Grant appropriate permissions to that identity — for example:

     

  • v-sgandrathi's avatar
    v-sgandrathi
    Community Support

    Hi mehr_sa,

     

    Thank you Ugk161610 for your answer and helpful explanation.

    Alongside the previously mentioned points, there are some Fabric-specific considerations when connecting to Azure SQL and Azure Storage from a User Data Function. When your Python script runs inside a User Data Function, it operates within the Fabric runtime, not on your local machine. Therefore, connection details like server names, database names, or storage account names should be stored securely in Fabric, such as in the Workspace Variable Library, rather than on your computer. This approach prevents hard-coding values and simplifies management across different environments.

    Ensure the identity used by the function has the necessary permissions in Azure. If using a managed identity or service principal, it needs to be added to Azure SQL as an Entra user with the appropriate database roles, and the SQL server firewall or network settings must allow access from Fabric. For Azure Storage, the same identity should have a suitable data access role, like Storage Blob Data Contributor, and the storage networking should permit Fabric to access the account.

    Lastly, User Data Functions are intended for short and efficient tasks. If your ETL script is lengthy, consider dividing it into smaller segments or handling extensive processing in a Fabric pipeline or notebook, with the UDF managing only the necessary function call operations.

    Thank you.

  • v-sgandrathi's avatar
    v-sgandrathi
    Community Support

    Hi mehr_sa,

     

    Just wanted to follow up and confirm that everything has been going well on this. Please let me know if there’s anything from our end.
    Please feel free to reach out Microsoft fabric community forum.

     

    Thank you.

  • v-sgandrathi's avatar
    v-sgandrathi
    Community Support

    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.