Table Storage Input Bindings
Table storage input bindings allow you to read data from an Azure Table Storage table directly into your Azure Function. This is a convenient way to access structured NoSQL data without writing explicit SDK code.
Supported Types
You can bind to the following types when using a Table Storage input binding:
string: Reads a single entity as a JSON string.dynamic(C#/PowerShell): Reads a single entity as a dynamic object.T(where T is a POCO class in C#): Reads a single entity and deserializes it into an object of type T. The properties of your class must match the column names in the table.IEnumerable(C#): Reads multiple entities.IQueryable(C#): Allows for more complex querying using LINQ.CloudTable: Provides access to the underlying Azure Table Storage SDK object.
Configuration
Table storage input bindings are configured in the function.json file. The primary parameters are:
type: Set totable.name: The name of the parameter in your function code that will hold the data.tableName: The name of the Azure Table Storage table to read from.connection: The name of the application setting that contains the Azure Storage connection string.partitionKey(optional): Specifies the partition to query.rowKey(optional): Specifies the row within the partition to retrieve.filter(optional): Allows you to specify an OData filter expression for more advanced querying.
Example function.json
{
"bindings": [
{
"name": "product",
"type": "table",
"tableName": "Products",
"partitionKey": "{category}",
"rowKey": "{productId}",
"connection": "AzureWebJobsStorage",
"direction": "in"
},
{
"name": "outputQueueItem",
"type": "queue",
"queueName": "output-messages",
"connection": "AzureWebJobsStorage",
"direction": "out"
}
],
"disabled": false
}
C# Example
This example shows a C# function that reads a product from Table Storage based on route parameters (e.g., /api/products/{category}/{productId}).
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
public static class GetProduct
{
public static class Product
{
public string PartitionKey { get; set; }
public string RowKey { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
}
[FunctionName("GetProduct")]
public static void Run(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = "products/{category}/{productId}")] HttpRequest req,
string category,
string productId,
[Table("Products", partitionKey = "{category}", rowKey = "{productId}", Connection = "AzureWebJobsStorage")] Product product,
ILogger log)
{
if (product == null)
{
log.LogWarning($"Product not found: Category={category}, ProductId={productId}");
// Handle not found case, e.g., return a 404
return;
}
log.LogInformation($"Retrieved product: {product.Name}");
// Process the product data
// ...
}
}
PowerShell Example
A PowerShell function reading a single entity.
param($req, $log)
$category = $req.Query.category
$productId = $req.Query.productId
# Assuming 'product' is defined in function.json as an input binding
# Example function.json:
# {
# "bindings": [
# {
# "name": "product",
# "type": "table",
# "tableName": "Products",
# "partitionKey": "{category}",
# "rowKey": "{productId}",
# "connection": "AzureWebJobsStorage",
# "direction": "in"
# }
# ], ...
# }
if ($product) {
$log.LogInformation("Retrieved product: $($product.Name)")
# Output the product details
Push-OutputBinding -Name resp -Value ([HttpResponseContext]@{
StatusCode = 200
Body = $product | ConvertTo-Json
})
} else {
$log.LogWarning("Product not found.")
Push-OutputBinding -Name resp -Value ([HttpResponseContext]@{
StatusCode = 404
Body = "Product not found"
})
}
Important Considerations:
- Ensure your
connectionstring is correctly configured in your application settings. - The
partitionKeyandrowKeyare fundamental to uniquely identifying an entity in Table Storage. - For complex queries beyond simple key lookups, consider using the
filterparameter or theCloudTablebinding type with the Table Storage SDK. - Performance can be optimized by designing your tables with appropriate partition keys.