We’ll publish one Serverless coding challenge a day, for 25 days. Solve it in the programming language of your choice and submit your solution via GitHub. We’ll showcase the best solutions every week and possibly in a final series recap!
Since PowerShell is now general available for Azure Function Apps, I decided to accept this challenge and see if I could keep it up using PowerShell as the only language. (Of course I could use all the services Azure has available).
Results so far
After 13 challenges, I have produced PowerShell Function Apps, Azure Automation Runbooks and logic apps. Along the way I got to use SignalR, Cognitive services, CosmosDB and Web apps. In this post I want to showcase all the functions I have written so far, hopefully to inspire you with the possibilities that Serverless en PowerShell give (and to join the challenge, it is still going!)
I do not have long guides on all these functions yet, there will absolutely be blogposts in the future for it. It does show the source codes though, and in every folder in my Github repo is a small readme with an explanation. This of course also means it contains spoilers, so if you haven’t done the challenges, try them for yourself first!
Disclaimer: This challenge meant I wrote a function app every day, so time was tight. This means the code is sometimes sloppy or lazy. Let’s call it YoloScripting :-). It is supposed to show the principals, but it is certainly not code you should copy for production.
The first challenge was a pretty straight forward, api-style function app. You can use Invoke-RestMethod to get a random result, like spinning a dreidel. Try it out like this
Invoke-RestMethod -Method GET -URI "https://4besday1.azurewebsites.net/api/spinthedreidel"
I went with a logic app for this challenge. There is supposed to be a message send every 10 minutes and then a separate stream of messages at different intervals, involving coffee.
The timer is triggered once at the relevant time (although a http trigger would work as well, as it only needs a boot). After that I worked with two different branches to get to the goal, email notifications. It is possible to handle it in one branch though.
So the question was to monitor a GitHub repository to see if PNG-files are added. If they are, the URL needs to be stored.
With use of the Github webhook option and a simple PowerShell function app, this could be achieved. The original challenge was to write the storage to a database, but I had very little time. For that reason I stored the output in a Storage queue, as I already knew how to do that. In day 4, I find out that was a good call.
The challenge was to have people add the meal they will be serving to a database through an API. That database has to be red through the function app as well.
So, the database connection. Between the available options I decided to go with CosmosDB. Well I was in for a challenge, I could not find any documentation whatsoever about Azure PowerShell Function app bindings with CosmosDB. It was there and it was supported. That’s it. So I went through a lot of trial and error and I got it working! Guess I have some inspiration for a new blog post. The next day I was announced the winner for this day by the Azure Advocated Team. So I am very happy with the results.
Get some messages that the children have send and give them a naughty or nice score automatically. Oh and the messages are in different languages.
So this was fun. The challenges sound so hard until you realize a lot of the questions can be resolved by out-of-the-box Azure Services. Those are some fun possibilities that I had never considered. So in the end this Powershell function app is connected to a Translation service, a text analytics service and keyvault for the secrets.
What is wrong with these children though?
Ah, A holiday I can relate to. Although we call it Sinterklaas in the Netherlands.
In this challenge a scheduler needed to be created for a chat program. So if you say you want to schedule something tomorrow, it should give you an alert tomorrow.
I went with Teams for the chat program and at this point I found one of the things that PowerShell function apps are not able to do: Run durable functions.
Fortunately, you can create a schedule from a runbook in an Azure Automation Account. And I already know how to trigger a runbook from a Logic App… Well it was challenging, there was a lot going on, but I got it to work
So I created a website where someone can search for a word. This word is then searched for in the Unsplash API.
Turns out, PowerShell does has some HTML-options, so this is not that hard. It’s still all within a function App which you can see here
The challenge here was to create a dynamic website with live updates that showed the status of the presents for santa. You were supposed to work with SignalR, which is a service in Azure. But I could not get this to work with PowerShell after trying and trying (I did get it to work in Day14, but that was mostly by copying and pasting other peoples ideas. More on that in a later post).
For this challenge, I decided on a workaround. I made a Function App again.
Ok ok, I didn’t use PowerShell for this one. I could have make it work, but this can be done a lot easier with a logic app. So I did.
The question was to get a Markdown file from a gist and produce an HTML file.
I thought I would be done quickly with this Function App, as PowerShell has a ConvertFrom-Markdown cmdlet. Only I could not get it to work within the function. Locally there was no problem. But when running the debug mode or deploying to Azure… No luck. I suspect this to be a bug in the cmdlet.
After a lot of trying and failing, I found out about the Github Api for markdown, and a sample script in a gist. That worked as well!
I spend some time with everything surrounding the function app. So you can call it as a restcall or in a browser, by adding the GistID. It can show you a HTML page, or the raw html file. You switch between those by adding “Raw=true” to the URL. If multiple files are in the gist, it combines multiple files in one output.
So… I changed the challenge and made it my own.
Get the best joke
Join the challenge
So these are all the fun challenges there were so far. Really the hardest thing to me was making time for these challenges and it’s the reason I am really not sure if I will last to the end, but I certainly will try! The challenges stay online and you can certainly complete them later if you stay away from the solution-blogs :). You can choose your own language, or join me in 25 days of Serverless in PowerShell. Find the challenges here.
The (lack of) cost of playing around
I just want to mention the costs of doing this challenge. I have been playing around in my Azure subscription with all these services all week. So I thought it might be fun to see what this had cost me, as I already knew it wasn’t going to be much.
I have done one thing to save a bit of money: I deleted the first CosmosDB container when I was done. The other functions were all left open and available. This is the cost from the first 7 days of challenges: