As part of the migration process of migrating our current ASP.NET Web API services to the Azure platform , I needed some mechanism to clear down the logs on a scheduled basis. The logs can quickly become quite large, so a means by which they could be cleared down was needed. I already had a stored procedure that could do this, so the next question was how to invoke this stored procedure automatically on a scheduled basis from Azure.
When I first looked into how I could achieve this, it seemed that there were typically many ways. The one that seemed the best fit for what I needed however, was to use Azure Automation in the form of runbooks. I won’t go into a detailed explanation of how to create these as there are plenty of guides on the Internet already including this one .
By using runbooks with Azure you can automate any process you want using Powershell scripting. You can create your runbook using either the Graphical-User-Interface, a Powershell Workflow or Powershell only. For my own specific requirements, I used the Powershell only option. I basically wrote a Powershell script (using the Azure scripting editor) that would invoke my stored procedure. I then tested this worked using the Azure automation Test Pane which allows you to run (and debug) your Powershell script-enabled runbook before you publish it. Once published, you can then setup a schedule for it so that it can be run automatically when needed.
If you are not familiar with the syntax to Powershell scripts, then you can use the Graphical-User-Interface which abstracts you away from having to know any Powershell by creating it for you under the covers. The Powershell Workflow option allows you to create a series of steps which together form a workflow. If you want a single, simple task to be performed then using the Powershell only option is perfect.
After discovering that Azure automation using runbooks was the solution for what I needed, it wasn’t a particularly arduous process to find out how to set this up. As with many things on the Azure platform, there are usually several ways of achieving the same thing, so it takes time researching and playing around to see which one best suits your needs.
It’s certainly been a lot of fun finding out though.