What are Function Triggers in Azure?

An Azure Function Trigger is a part of a function’s stack that tells Azure how the function is invoked. The most common function triggers are HTTP, Timer, and Blob:

  • The HTTP trigger tells Azure that the function will be invoked through an HTTP request. An example is a GET request used to obtain the most recent transactions in a banking app.
  • The Timer trigger tells Azure that the function should be executed at specific times. An example is a business app that generates sales reports by 6 pm daily.
  • Blob storage describes a function whose logic is executed when a file is uploaded or updated in an Azure Blob Storage instance.
widget

Trigger types

There are other trigger types aside from HTTP, Timer, and Blob:

Type Purpose
Timer Execute a function at a set interval.
HTTP Execute a function when an HTTP request is received.
Blob Execute a function when a file is uploaded or updated in Azure Blob storage.
Queue Execute a function when a message is added to an Azure Storage queue.
Azure Cosmos DB Execute a function when a document changes in a collection.
Event Hub Execute a function when an event hub receives a new event.

Timer triggers

Timer Triggers are defined using CRON syntax. Time Triggers CRON syntax puts the seconds first, then the minutes, hours, days, months, and days of the week.

widget

LIFX bulb example

The widget below shows a serverless timer function that sets the color of a LIFX bulb based on the outside temperature. The function fires every five minutes as indicated in the cron definition in the function.json file:

Uses of time triggers

  1. Generating reports
  2. Cleaning a database
  3. Sending notifications

HTTP triggers

HTTP triggers execute function logic when they receive a HTTP request. Examples of HTTP requests are:

  1. GET request for requesting data
  2. POST request for creating resources
  3. PUT request for modifying resources
  4. DELETE requests for deleting resources

Several HTTP verb handlers can be contained in a function. This means that an entire application can be composed of serverless functions.

A sample HTTP trigger function is given below. It is similar to the typical express routing handler function, however, the serverless function below uses an HTTP post request to submit a link to a given subreddit:

HTTP triggers can be used for building:

  1. Webforms
  2. Mobile applications
  3. Aggregators

Blob triggers

This trigger executes a function when a file is uploaded or updated in Azure Blob storage. This function type can be used to:

  1. Notify an admin that a file has been uploaded
  2. Convert a newly uploaded image file to a thumbnail
  3. Update a database with an image’s metadata

Other trigger types

Several other trigger types exist as Azure has trigger types for most use cases. This versatility allows developers to create a wide variety of applications using Azure Functions.