DEV Community

Split Blog for Split Software

Posted on • Originally published at split.io on

8 Things You Might Not Know About Azure Functions

Azure Functions is an available-on-demand cloud service that provides all the continually updated infrastructure and resources needed to run your applications. If you’re a .NET developer you’ve almost certainly used it before in your applications, but here are a few things you probably didn’t know it could do that are sure to save you some time or make your life easier.

1. With Azure Functions you can write in multiple languages

There are three versions of the Azure Functions Runtime and you can use various languages in each version. Notably, in version 3.x you can use:

  • C# in .NET 5.0 and below
  • F# in .NET Core 3.1 and below
  • Java 8 and 11
  • Python 3.6 through 3.9-Preview
  • JavaScript Node 14, 12, and 10
  • TypeScript
  • PowerShell 7.0 and Core 6

2. You can use the Azure Functions host on multiple platforms

The Azure Functions host is written in .NET Core which means it can operate on any operating system that has .NET Core installed.

How awesome is that? That means your team can work on the same project regardless of their personal operating system.

3. With Azure Functions you can run and debug locally

You can run and debug Azure Functions locally using the Azure Functions Runtime. You can also test a function without having to install any packages. The best part? It runs on Windows, Mac, and most versions of Linux.

The advantage here is that you can debug through the local Azure Host to see exactly what’s going on in your application. Since it’s the exact same Azure Host used by Azure online you can get a pretty good look under the hood and see what your application is really doing. Now you don’t have to rely on error logs and logging to try and figure out what happened if your application crashes.

4. You can integrate into Visual Studio Code with Azure Functions

The Azure Functions crew teamed up with Visual Studio to build an awesome extension. It allows you to create, deploy, and even stream logs locally in Visual Studio Code.

That means you don’t have to leave the editor to manage your functions and can continue to work on your code without breaking your flow.

Below is an example of editing a C# function on Mac OSX with Visual Studio Code, deploying it to the Azure Portal, and exercising it from the command line:

5. You can trigger Azure Functions in a ton of different ways

Things that trigger a function include; insertion into Blob Storage, Cosmos DB, Event Grid, Event Hub, Microsoft Graph, Storage Queue and Service Bus, and a call from an HTTP endpoint.

For instance, you could have an Azure Function execute every time an HTTP request is made to your API. The function could track and roll up information like client IP address, latency, user agent, etc. This is super useful in having an out-of-band way to track events that you don’t want to necessarily embed in your core code. It could also be very useful for asynchronous events. You might have an endpoint that kicks off a function and returns immediately to your client after kicking off an Azure Function. Your client could then poll an endpoint to see if the Azure Function was done and when it was, could report back a result.

6. You can chain Azure Functions

You can chain multiple Azure Functions together! It’s possible to call a function from a function, and in certain use cases that might be desirable.

For anything more complex, it’s much better to use Azure Durable Functions as it was made to help orchestrate function chaining. The big advantage here is that Durable Functions are stateful where standard Functions are stateless.

Using Durable Functions to orchestrate will allow you to process multiple functions with shared data and you’ll be able to call your functions in several different patterns.

Setting up an Azure Durable Function looks like this in either Visual Studio or VS Code:

A. Create a Durable Functions Orchestrator file

Add a New Item in Visual Studio

Azure Functions: Create Function in CS Code

B. Your Orchestration file will look like this:

const df = require("durable-functions");

module.exports = df.orchestrator(function* (context) {
const outputs = [];

// Replace "Hello" with the name of your Durable Activity Function.
outputs.push(yield context.df.callActivity("Hello", "Tokyo"));
outputs.push(yield context.df.callActivity("Hello", "Seattle"));
outputs.push(yield context.df.callActivity("Hello", "London"));

// returns ["Hello Tokyo!", "Hello Seattle!", "Hello London!"]
return outputs;
});
Enter fullscreen mode Exit fullscreen mode

This is a standard chain pattern that calls one function after the other. You can also use the Fan-out/Fan-in pattern which allows you to run multiple functions in parallel.

C. When you deploy to Azure you’ll be prompted to attach the function to a storage account because you added the Orchestration file. If you don’t have one you’ll be prompted to create one

7. You can bind Azure Functions

Binding allows you to communicate with other services like Service Bus, Cosmos DB, Webhooks, SignalR, and more! Bindings can be connected as input bindings, output bindings, or both. Data from bindings is provided to the function as parameters.

Imagine being able to pull in data from almost anywhere with very little setup and overhead, and use that in your functions. Someone triggers a webhook or some other event in a completely different service and suddenly your functions are made aware of that and can not only react to the event but receive or pass data somewhere else at the same time.

An example would be; someone fills out a form in a third-party application* triggering an event that your function was listening for. Your function can immediately receive data from the event and process it without involving anyone.

*The third party application would have to trigger an event in the Supported bindings and you’d have to have access from that third party.

8. You can integrate Azure Functions with Split for CI/CD

You can create Azure functions that call the Split API allowing you to control your splits through in a variety of situations.

Using the supported Azure Triggers and Bindings talked about above you could automate control of your splits in a variety of situations giving you more control and flexibility. You could turn your splits on and off in response to a webhook being called.

You could rapidly add users to segments when they’re added to a database without having to alter any code in that workflow. Azure Functions would watch these supported applications and respond to their events with the given data to act on your splits the way you want to.

Learn More About Modern Software Delivery and Experimentation

I hope you enjoyed the post. It was really fun to learn more about Azure Functions and how they can be used to improve your workflow and continuous delivery. What are your favorite tips and tricks about Azure Functions? Hit me up on Twitter @Programazing and let me know!

If you liked this blog post check out a few of my favorites below.

Simultaneous Experimentation: Run Multiple A/B Tests Concurrently

The Journey to Improve our Web SDKs

Continuous Deployment in Node.js with GitHub Actions and Heroku



Make sure you catch all our new releases as they come out!

Follow us on Twitter @splitsoftware, and subscribe to our YouTubechannel.

Top comments (0)