Azure Functions Table Trigger Bindings

This document details how to use Azure Table Storage as a trigger for Azure Functions. The Table trigger allows your function to execute in response to changes in an Azure Table Storage entity.

Overview

The Table trigger monitors a specific Azure Table Storage table for new or updated entities. When an entity meets the trigger criteria (e.g., it's a new entry or has specific properties), the function is invoked with the entity data.

Supported Operations

The Table trigger primarily focuses on reacting to the insertion of new entities. While it doesn't directly trigger on updates or deletions in the same way as some other triggers, you can implement custom logic to handle these scenarios using input and output bindings.

Configuration

To configure a Table trigger, you'll need to define it in your function's configuration file (e.g., function.json) and provide connection details for your Azure Storage account.

function.json Example


{
  "scriptFile": "run.csx",
  "bindings": [
    {
      "name": "myTableItem",
      "type": "tableTrigger",
      "direction": "in",
      "tableName": "MyDynamicTable",
      "connection": "AzureWebJobsStorage"
    }
  ]
}
            

Table Trigger Properties

Programming Model

The way you receive the trigger data depends on the language you are using for your Azure Function.

C# Example


using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;

public static class TableTriggerFunction
{
    [FunctionName("TableTriggerFunction")]
    public static void Run(
        [TableTrigger("MyDynamicTable", Connection = "AzureWebJobsStorage")] MyEntity myTableItem,
        ILogger log)
    {
        log.LogInformation($"C# Table trigger function processed row with PartitionKey: {myTableItem.PartitionKey} and RowKey: {myTableItem.RowKey}");
        log.LogInformation($"Data: {myTableItem.Data}");
    }
}

public class MyEntity
{
    public string PartitionKey { get; set; }
    public string RowKey { get; set; }
    public DateTime Timestamp { get; set; }
    public string Data { get; set; }
}
            

JavaScript Example


module.exports = async function (context, myTableItem) {
    context.log('JavaScript Table trigger function processed row');
    context.log('PartitionKey:', myTableItem.PartitionKey);
    context.log('RowKey:', myTableItem.RowKey);
    context.log('Data:', myTableItem.Data);
};
            

Python Example


import logging

import azure.functions as func

def main(myTableItem: func.DocumentList) -> None:
    logging.info('Python Table trigger function processed a table item.')
    for item in myTableItem:
        logging.info(f'PartitionKey: {item.get("PartitionKey")}')
        logging.info(f'RowKey: {item.get("RowKey")}')
        logging.info(f'Data: {item.get("Data")}')
            

Entity Properties

The triggered entity will contain standard Azure Table Storage properties, including:

Any custom properties you've defined in your table entities will also be available.

Scenarios and Best Practices

Important Considerations

The Table trigger is best suited for reacting to the insertion of new entities. For handling updates or deletions, consider using other Azure services like Azure Event Grid or implementing a polling mechanism with input bindings.

Note on Performance

If your table experiences a very high volume of writes, ensure your function app has adequate scaling configured to handle the load. Monitor your function's execution times and resource usage.

Tip for Complex Data

If your table entities contain complex or large data structures, consider serializing and deserializing them within your function logic for easier management.

Limitations

Related Bindings

You can combine the Table trigger with other bindings: