Azure Functions Documentation

Table Storage Input Bindings

Table storage input bindings allow your Azure Functions to read data from Azure Table Storage. This is a NoSQL key-attribute store that can store large amounts of structured, non-relational data.

When to use Table Storage Input Bindings

Configuration

To configure a Table Storage input binding, you define it in your function.json file (for JavaScript, Python, and PowerShell) or using attributes (for C#).

function.json Example (Node.js)

{
  "scriptFile": "index.js",
  "bindings": [
    {
      "name": "inputTable",
      "type": "table",
      "direction": "in",
      "tableName": "MyDataTable",
      "connection": "AzureWebJobsStorage",
      "partitionKey": "{Query.partitionKey}",
      "rowKey": "{Query.rowKey}"
    },
    {
      "name": "outputBlob",
      "type": "blob",
      "direction": "out",
      "path": "output/{Query.fileName}.txt",
      "connection": "AzureWebJobsStorage"
    }
  ]
}

C# Attribute Example

[FunctionName("ReadTableRow")]
public static void ReadTableRow(
    [HttpTrigger(AuthorizationLevel.Function, "get", Route = "read/{partitionKey}/{rowKey}")] HttpRequest req,
    [Table("MyDataTable", "{partitionKey}", "{rowKey}", Connection = "AzureWebJobsStorage")] MyEntity entity,
    ILogger log)
{
    if (entity == null)
    {
        log.LogInformation("Entity not found.");
        return;
    }
    log.LogInformation($"Found entity: PartitionKey={entity.PartitionKey}, RowKey={entity.RowKey}, Data={entity.Data}");
}

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

Binding Parameters

Parameter Description Required
name The name of the variable that represents the input data in your function code. Yes
type Must be table for Table Storage input bindings. Yes
direction Must be in for input bindings. Yes
tableName The name of the Azure Table to read from. Yes
connection The name of the app setting that contains the Azure Storage connection string. Defaults to AzureWebJobsStorage. No
partitionKey Specifies the partition key for the entity. Can be a static value or a binding expression. Yes (if reading a specific entity)
rowKey Specifies the row key for the entity. Can be a static value or a binding expression. Yes (if reading a specific entity)

Reading Multiple Rows or Querying

To read multiple rows or perform more complex queries, you can use the Table Storage SDK directly within your function. The input binding is primarily designed for retrieving a single, specific entity using its partition and row keys.

Tip: For retrieving multiple rows or filtering, consider injecting a CloudTable object using the Microsoft.Azure.WebJobs.Extensions.Storage.CloudTable type (in C#) or using the Azure Storage SDK.

Data Types

The data read from Table Storage will typically be deserialized into a dictionary or a POCO (Plain Old CLR Object) depending on your function's language and how you define your parameters.

Example Scenario

Imagine you have a table named UserSettings with PartitionKey representing a user ID and RowKey representing a setting type (e.g., 'Theme', 'Notifications'). An input binding could fetch a specific user's theme preference.

Input Binding (function.json)

{
  "name": "userSetting",
  "type": "table",
  "direction": "in",
  "tableName": "UserSettings",
  "partitionKey": "{User}",
  "rowKey": "Theme"
}

Function Code (Node.js)

module.exports = async function (context, userSetting) {
    if (userSetting) {
        context.log(`User theme: ${userSetting.Value}`);
    } else {
        context.log('User setting not found.');
    }
};

This setup efficiently retrieves specific data points from your Table Storage without needing to write boilerplate SDK code for common lookups.