Three Reasons To Consider PowerShell for Serverless Functions

Posted by

In a move that surprised many, myself included, AWS added support for PowerShell Core to its popular serverless platform, Lambda. Azure’s competing product, Functions, also supports PowerShell, albeit in a less official manner.

PowerShell isn’t usually a go-to language for software developers. So why are we seeing the big cloud providers adopting it for their serverless platforms? There are a few reasons that I can think of, but before I get into that, let’s quickly review the flavours of PowerShell supported on AWS and Azure.

A Tale of Two Cloud Providers

The AWS Lambda support for PowerShell is built on PowerShell Core, the actively maintained, .NET Core-based language that runs cross-platform. Unfortunately, it means that you won’t have access to all the modules available in Windows PowerShell. It will, however, give you the ability to manage most aspects of your AWS infrastructure from inside a Lambda function.

The Azure Functions support, on the other hand, is a bit more complicated to explain. The two runtimes for Azure Functions, Version 1 and Version 2, provide access to different versions of PowerShell. The V1 runtime is based on the .NET Framework and therefore runs Windows PowerShell. Its usage is considered experimental, and I expect it to stay that way since work now appears to be solely focused on the V2 runtime.

The Functions V2 Runtime, on the other hand, is built on .NET Core, which brings us right back to PowerShell Core. Sure enough, a public preview of PowerShell Core in Functions was announced at the end of April. The nature of a preview version means that some behaviours could change, bugs might be lurking around, and a General Availability date is yet to be announced.

With all that in mind, what should you consider using PowerShell Core for?

#1 Automate Cloud Maintenance

We often don’t realize how many of our daily tasks could be automated. In some cases, it can be a big productivity boost that reduces the amount of context switching we do in a day.

Here are some ideas of tasks that could run as part of a schedule, or even as triggers to cloud events. Hopefully it’ll stimulate some ideas for you:

  • Hooks to perform tasks in build or release pipelines.
  • Cleanup stale branches in a repository.
  • Scan for open ports that should remain closed at all times.
  • Tear down non-production environments outside of working hours.
  • Shut down large, expensive resources when they aren’t in use.
  • Refresh data from production to non-production environments.

Of course, this list only scratches the surface. But these types of tasks are a perfect fit for PowerShell serverless functions, more so than a language like C#.

#2 Make Script Executions More Visible

Many organizations have PowerShell scripts that perform all sorts of tasks. Those scripts are usually not in source control, are run manually, and only known by a few people. For all these reasons, the scripts have a tendency to get misplaced in the long run.

Lambda and Functions give us the opportunity to shed some light on these scripts by putting a proper process in place for versioning and deployment. The first step, of course, is to check them into source control. Once that’s done, the next step is to create a deployment pipeline in a tool like Azure DevOps or Octopus Deploy. Standardizing the deployment process in this way means that the latest version of the PowerShell script will always be executed by the serverless platform.

Determining cause and effect is easy when you know what did or didn’t run, and executing PowerShell scripts as serverless functions accomplishes just that. Both Functions and Lambda record each execution to their respective logging frameworks, making it easy to trace what was changed when.

#3 Get Ops Involved

We’ve made big strides to bring development and operations teams closer together over the past years. An operations team that writes and runs scripts in the same paradigms as the development team intrinsically brings both teams together like never before.

There is an opportunity to share knowledge, skills, and work together to improve shared processes. Ultimately, it helps to move the entire organization forward.

PowerShell Is Here to Stay

One thing is clear to me from all this: PowerShell is having a rebirth in the cloud. It’s a must-have skill in the tool belt for anyone working in the Microsoft ecosystem.

One comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s