HTTP Trigger
Enables a function to respond to HTTP requests. The function can be invoked using a URL.
Example (C#)
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
public static class HttpExample
{
[FunctionName("HttpExample")]
public static IActionResult Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req)
{
string name = req.Query["name"];
return new OkObjectResult($"Hello, {name ?? "world"}");
}
}
Timer Trigger
Runs a function on a schedule using CRON expressions.
Example (JavaScript)
module.exports = async function (context, myTimer) {
var timeStamp = new Date().toISOString();
context.log('Timer trigger function ran at', timeStamp);
};
function.json
{
"bindings": [
{
"name": "myTimer",
"type": "timerTrigger",
"direction": "in",
"schedule": "0 */5 * * * *"
}
]
}
Blob Storage Trigger
Invoked when a new or updated blob is detected in a storage container.
Example (Python)
import logging
import azure.functions as func
def main(blob: func.InputStream):
logging.info(f"Blob trigger processed blob\n"
f"Name: {blob.name}\n"
f"Size: {blob.length} bytes")
function.json
{
"bindings": [
{
"name": "blob",
"type": "blobTrigger",
"direction": "in",
"path": "samples-workitems/{name}",
"connection": "AzureWebJobsStorage"
}
]
}
Queue Storage Trigger
Runs when a new message appears in an Azure Storage queue.
Example (C#)
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
public static class QueueExample
{
[FunctionName("QueueExample")]
public static void Run(
[QueueTrigger("myqueue-items", Connection = "AzureWebJobsStorage")] string myQueueItem,
ILogger log)
{
log.LogInformation($"C# Queue trigger function processed: {myQueueItem}");
}
}
Cosmos DB Trigger
Triggers when documents are created or updated in a Cosmos DB container.
Example (JavaScript)
module.exports = async function (context, documents) {
if (!!documents && documents.length > 0) {
context.log('Document Id:', documents[0].id);
}
};
function.json
{
"bindings": [
{
"type": "cosmosDBTrigger",
"name": "documents",
"direction": "in",
"leaseCollectionName": "leases",
"connectionStringSetting": "CosmosDBConnection",
"databaseName": "mydb",
"collectionName": "mycoll"
}
]
}
Event Grid Trigger
Invoked by Event Grid events such as resource creation, deletion, or custom events.
Example (C#)
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.EventGrid.Models;
using Microsoft.Extensions.Logging;
public static class EventGridExample
{
[FunctionName("EventGridExample")]
public static void Run(
[EventGridTrigger] EventGridEvent eventGridEvent,
ILogger log)
{
log.LogInformation($"Event Grid trigger received: {eventGridEvent.EventType}");
}
}
Event Hub Trigger
Processes events arriving in an Azure Event Hub.
Example (Java)
public class EventHubTriggerFunction {
@FunctionName("EventHubProcessor")
public void run(
@EventHubTrigger(name = "msg",
eventHubName = "myhub",
connection = "EventHubConnection") String[] messages,
final ExecutionContext context) {
for (String message : messages) {
context.getLogger().info("Event Hub message: " + message);
}
}
}
Service Bus Trigger
Triggered when a message arrives on a Service Bus queue or subscription.
Example (JavaScript)
module.exports = async function (context, mySbMsg) {
context.log('Service Bus queue trigger processed message', mySbMsg);
};
function.json
{
"bindings": [
{
"type": "serviceBusTrigger",
"name": "mySbMsg",
"direction": "in",
"queueName": "myqueue",
"connection": "ServiceBusConnection"
}
]
}