Azure Functions Reference

This document provides a comprehensive reference for Azure Functions, covering triggers, bindings, configuration, runtime details, and best practices.

Triggers

Triggers define how a Function is invoked. They are the entry points for your function's execution. Azure Functions supports a wide variety of triggers:

HTTP Trigger Example


{
  "scriptFile": "run.csx",
  "entryPoint": "Run",
  "bindings": [
    {
      "authLevel": "function",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": [
        "get",
        "post"
      ]
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    }
  ]
}
            

Bindings

Bindings allow you to declaratively connect to other Azure services and external data sources. They reduce the amount of boilerplate code you need to write.

Input and Output Bindings

Bindings can be configured as either input or output bindings. Input bindings provide data to your function, while output bindings send data from your function to another service.

Binding Type Description Direction
Azure Blob Storage Read/write blobs to Azure Blob Storage. Input/Output
Azure Table Storage Read/write entities to Azure Table Storage. Input/Output
Azure Cosmos DB Read documents from or write documents to Azure Cosmos DB. Input/Output
Service Bus Queue/Topic Send messages to or receive messages from Service Bus. Input/Output
Twilio Send SMS messages via Twilio. Output

Cosmos DB Output Binding Example


{
  "scriptFile": "run.js",
  "entryPoint": "run",
  "bindings": [
    {
      "authLevel": "function",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req"
    },
    {
      "type": "cosmosDB",
      "direction": "out",
      "name": "outputDocument",
      "databaseName": "ToDoList",
      "collectionName": "Items",
      "connectionStringSetting": "CosmosDBConnection"
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    }
  ]
}
            

Configuration

Azure Functions can be configured using various methods:

Note: It's best practice to store sensitive information like connection strings in Application Settings rather than directly in function.json or host.json.

Runtime

Azure Functions are supported across multiple runtime stacks, allowing you to use your preferred programming language:

Runtime Versions

You can specify the runtime version in your host.json file. For example:


{
  "version": "2.0",
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[3.*, 4.0.0)"
  }
}
            

Best Practices

To build robust and efficient Azure Functions, consider the following best practices:

Tip: For long-running or computationally intensive tasks, consider using Durable Functions to orchestrate complex workflows.