Sometimes you need to run some code – somewhere. You don’t care where. But clients need to be able to get to it. You don’t want servers, VMs, or web apps, just something very lightweight. So Azure Functions sounded like a workable solution. I’m starting from a blank slate:
I clicked to add an app and filled in the blanks:
Resources were successfully created and deployed:
From there, I can click “Go to resource” to get to here:
And then “New function” to create one. I’ll choose “In-portal” to keep things simple:
And then “Webhook + API”:
So now I’m left with a code sample that takes a “name” query parameter and writes a response containing that value. So it’s a good starting point:
But I want to use a counter, so I am going to add an input:
And I can give my new table a name:
While I’m at it, I’ll make this anonymous and turn off POST requests (not necessary in my case, GET is fine):
Let’s take a detour into the Azure Table objects in the storage account tied to this function:
I can click to add one and specify the name, countTable, but to see what’s in it I need to switch to Storage Explorer, where I can add an entity (row) and specify values:
How exciting, one column added. But it gets me set up for what I really wanted to do: Create a function that generates a sequential computer name. That shouldn’t be too hard, but I chose to do it with C# script (basically, code compiled on the fly) which made debugging a little bit more challenging. And I added in Azure table storage, which I hadn’t used before either. So let’s just say it took me a couple of hours to get to this:
The code itself can be found in an attachment at the bottom of this blog post.
So I can then call it pretty easily from PowerShell. The simplest example:
Magic. That’s a little more straight-forward than the last time I did something similar, and it’s entirely in the cloud.