Menu Close

25 days of serverless in PowerShell – Halfway there

On December first, The Azure Advocates announced 25 days of Serverless.
This means they give out daily challenges to help people get into Serverless. I decided to join using only PowerShell!

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. 

25Days of serverless

Day 1

The challenge: Serverless Dreidel

My solution

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 ""

Day 2

The challenge: Lucy’s Dilemma

My solution

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.

25 days of serverless day 2


Day 3

The Challenge: Secret Santa’s Furry Friends

My solution

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.

Day 4

The Challenge: Potluck diner

My solution

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.

Day 5

The Challenge: Naughty or Nice

My solution

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?
25 days of serverless day 5

Day 6

The Challenge: Saint Nicholas day

My solution

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

day 7

Day 7

The Challenge: la quema del diablo

My solution

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

Day 8

The Challenge: Status update

My solution

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.

The function SetStatus is an API for the elves to set the current status.
The function Front shows a website with the current status and when it was set.
To get some sort of live updates there, I have set the webpage to reload every 30 seconds.
25 days of serverless HTML

Day 9

The Challenge: Ebenezer Scrooge

My solution

This challenge was to create a bot that can respond if someone creates an issue on a GitHub repository. Again, no problem with a PowerShell function App, if combined with the Github API.
Github connection

Day 10

The Challenge: Daily Aggregated Deals

My solution

So the challenge is to create a website that shows a bunch of tweets with a hashtag in them.
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.
It was a bit of work to get the HTML to parse correctly from the storage blob.
25 days of serverless flow

Day 11

The Challenge: Wishmaster 2000

My solution

So this challenge is big. Create a system where children can post their requests, store them in a database so Santa can view them. Also, the elves need to be notified when a new wish is entered. A lot of stuff, but it is mostly about combining all the previous challenges.  No problem for a PowerShell function app!

Day 12

The Challenge: Saint Nicholas day

My solution

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.

For example, you can use this link in your browser:
(click it, is will give you a picture of my dog!)
This is based on the this gist.
To view the HTML, Add “Raw=true” to the URL:

Day 13

The Challenge: The yule lads

My solution

And on the thirteenth day… it happened. A challenge I couldn’t solve with Powershell :(.
The challenge was completely aimed at Python and machine machine learning. I was not able to solve it.

So… I changed the challenge and made it my own.

Get the best joke

I have created a blob triggered function app that responses to the dataset that is uploaded.
It first takes all the entries in the dataset and uses the Sentiment analysis service to give every joke a score. This is the base to work on and the jokes with their scores are stored in a CosmosDB.
When the tricksters want to get a joke, they can call on
This website will give one of the jokes that is in the top 10 of the highest scores in the database.
The trickster can then rate if the joke is funny or not. If they enter that the joke isn’t funny, the score is reduced by 0.10 points.
If it is funny, it is increased by .10 points. The new data is written to the database.
So if enough tricksters use the joke-site, you should be left with the 10 funniest jokes in the database.
There you go, still a very good use case for a PowerShell function app :).

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:


Leave a Reply

Your email address will not be published. Required fields are marked *