The focus of this article is for you to learn some of the use cases for Azure Functions. Before we dive into those details, let’s do a quick review of what exactly are Azure Functions.
Azure Functions are an Azure compute service that allows you to run code with no concern for any of the underlying infrastructure. They are event-driven and are usually small, focused workloads that execute quickly. With Functions being event-driven, that means something must initiate the event to occur, and in this case, the initiator is referred to as a Trigger. To give you a better understanding of Azure Function usage, you will need a better understanding of the events that cause a function to run. An Azure Function will be executed by one of the following triggers:
- HTTP/WebHook trigger
- Timer trigger
- Azure Blob Storage trigger
- Azure Queue Storage trigger
- Azure Service Bus Queue/Topic trigger
- Azure Event Hub trigger
- Azure Cosmos DB trigger
- IoT Hub (Event Hub) trigger
- Azure Event Grid trigger
As you can see, there is no shortage of triggers to react to different events or Azure services. Because of the numerous triggers to choose from, it might not always be obvious what the best use cases are for each Azure Function. I would like to help ease that concern for you as well as hopefully provide some new use cases for Azure Functions. For this article, we will be exploring just a subset of those triggers: HTTP/WebHook, Timer, Azure Storage Blobs, and queue.
HTTP/WebHook triggers execute whenever an HTTP request is received, responding based on data in the body or query string:
- Host a website (view some code)
- Post Application Insights Alerts to Microsoft Teams (view some code)
- Implement a WebHook (view some code)
- Create a game (view some code)
Functions that use the Timer trigger will run on a specified schedule. This means that this trigger is handy for executing timer-based processing tasks.
- Start / Stop VMs on a schedule – (view some code)
- Periodically train a machine learning model and then expose an API endpoint (view some code)
- Polling blob storage (view some code)
As stated earlier, it can be challenging for you to know the best scenarios for using Azure Functions. To make matters a little more complicated, knowledge of each functions’ trigger needs to be considered. For instance, while discussing the use cases for the timer trigger, it was mentioned that a timer could be used to poll Azure Blob Storage. This approach will technically work; however, a more direct trigger exists that interacts with Blob Storage, and that is the Azure Blob Storage trigger, which will be discussed next.
Azure Blob Storage Trigger
The Blob Storage trigger is designed to run whenever a blob is added to a specified storage container.
- Uncompress zip files that are uploaded to Blob Storage (view some code)
- Resizing image files uploaded to Blob Storage (view some code)
- Extracting data from files based upon file type
Azure Storage Queue Trigger
The final trigger we will discuss runs whenever a message is added to a specified Azure Storage queue.
- Decoupling the interaction between multiple systems by reacting to messages added to a queue (view some code)
- Act as a consumer in a Durable Function fan-out solution (view some code)
Azure Functions allow for a wide range of scenarios to be handled while simplifying the process of deploying code to Azure. In most cases, as can be seen from the referenced code, a complete solution for a problem can be achieved by combining several Azure Functions! This article serves as part 1 in a series of articles discussing the uses of Azure Functions.