Of late, I was working on a customer requirement, which is to start a runbook. Yes, many would have done it through logic apps, function app, or webhooks. This blog post is to walk you through the steps to create an Azure Function to start an Azure Automation runbook .
Our goal is to wait until the job completes and fetch the output. If you are familiar with C#, the ASYNC programming pattern helps you to achieve it quickly. In my case, it’s an IT Pro way. Yes, I am not good with ASYNC programming. So, I managed to convert my PowerShell script to C#, which solved the issue.
If the Azure automation account runbook job takes more than 230 seconds, a timeout occurs. The 230 seconds of timeout settings can’t be tuned, and it’s a hard set value. Azure Functions Start Azure Automation Runbook
The runbook we need to start has three parameters as illustrated below
For our demo purpose, the runbook should collect parameters and prints the data as JSON objects. Below, code does it.
If you are familiar with PowerShell, the below snippet is easy to understand.
The code above is to start an Azure automation account runbook and retrieves the output.
Do you think it’s reinventing the wheel? No, it is not. It’s an alternative approach to avoid Az modules.
A simple “DO WHILE” loop is here to wait until the job gets completed and retrieves it.
The below snippet is to invoke the Azure function app.
We have covered the steps to use an Azure Function to start an Azure automation runbook, wait till the job completes and fetch the output. Indeed, there are multiple ways and approaches to do the same. If you have found one, please feel free to share your feedback. In my next blog post, we show the use case of a timer trigger with a real-world example.
New 2019 Edition.
Download This New eBook Now!