Following on from a previous blog post that I wrote a few months ago where I got an Azure Data Factory Pipeline run status with an Azure Function (link below). I recently found the need to create something very similar to execute any pipeline from an Azure Function.
Happily, this pipeline execution is basically the example provided by Microsoft in the documentation for the Data Factory .NET SDK (link also below). Given this I’m not taking any credit for the bulk of the function code. However, I did need to extend the body of the request for the function to accept any amount of pipeline parameters.
The reason for needing such an Azure Function is because currently the Data Factory activity to execute another pipeline is not dynamic. The name of the downstream pipeline called can not be driven by metadata which upsets me greatly, everything should be dynamic 🙂
Replacing this activity with an Azure Function activity is less than ideal as this then presents the following challenges:
- Making the Azure Function block and wait until the pipeline returns means potentially a long running durable function is required.
- Calling an Azure Functions mean paying for the additional compute to a achieve the same behaviour which we are already paying for in Data Factory is used directly.
- Authentication needs to be handled from Data Factory to the Azure Function App and then from the Azure Function back to the same Data Factory. This should be done via our application settings and handled in our release pipelines, rather than passed in the function body. No trolls please, I know.
With an understanding of these important caveats here’s an overview of the solution.
Note; I used .NET Core 3.0 for the below function.
For the function itself, hopefully this is fairly intuitive once you’ve created your DataFactoryManagementClient and authenticated.
The only thing to be careful of is not using the CreateOrUpdateWithHttpMessagesAsync method by mistake. Make sure its Create Run. Sounds really obvious, but when you get code drunk names blur together and the very different method overloads will have you confused for hours!…. According to a friend 🙂
Body JSON without Pipeline Parameters
Body JSON with Pipeline Parameters
The pipeline parameters attributes can contain as many parameters as you want and basically just ingests them into the overloaded method; CreateRunWithHttpMessagesAsync as a Dictionary of string and object.
Data Factory doesn’t validate the parameter names so you can send anything. I just assumes the names passed are identical to the names of the actual pipeline parameters. If so, the values are simply mapped across.
Just Give Me The Code!
Ok! Here you go… ExecutePipeline.cs
The full solution is in the same Blob Support Content GitHub repository if you’d like to use the Visual Studio Solution.
I hope you found this post helpful.
Many thanks for reading.