Azure Functions Settings
This document provides a comprehensive guide to configuring and managing settings for Azure Functions.
Configuration Sources
Azure Functions supports multiple configuration sources, allowing you to manage settings effectively across different environments.
Application Settings
Application settings are key-value pairs that are accessible by your function code. These are ideal for configuration data specific to your application, such as connection strings, API keys, or feature flags.
Settings can be managed through:
- The Azure portal.
- The Azure CLI.
- ARM templates or Bicep.
- Environment variables (for local development and containerized deployments).
Connection Strings
Connection strings are a special type of application setting used to store connection information for external services like databases or storage accounts. Azure Functions provides specific environment variables for accessing these:
AzureWebJobsStorage
: Used by the Functions runtime for managing triggers and logging.WEBSITE_CONTENTAZUREFILECONNECTIONSTRING
: Used for remote debugging and accessing function content in Azure Files.
Managing Settings
Azure Portal
Navigate to your Azure Function App in the Azure portal. In the left-hand navigation menu, under "Settings," select "Configuration." Here you can add, edit, and delete application settings and connection strings.
Azure CLI
You can manage settings using the Azure CLI commands:
# Get all settings
az functionapp config appsettings list --name <function_app_name> --resource-group <resource_group_name>
# Add or update a setting
az functionapp config appsettings set --name <function_app_name> --resource-group <resource_group_name> --settings MySetting=MyValue
# Delete a setting
az functionapp config appsettings delete --name <function_app_name> --resource-group <resource_group_name> --setting-names MySetting
Accessing Settings in Code
Settings are injected as environment variables into your function's execution context. The method for accessing them varies slightly by language:
C#
var settingValue = Environment.GetEnvironmentVariable("MySetting");
var connectionString = Environment.GetEnvironmentVariable("MyConnectionString");
JavaScript
const settingValue = process.env.MySetting;
const connectionString = process.env.MyConnectionString;
Python
import os
setting_value = os.environ.get("MySetting")
connection_string = os.environ.get("MyConnectionString")
Special Settings
Host Settings
Some settings control the behavior of the Functions host itself. These are typically managed in the host.json
file.
Example host.json
snippet for controlling HTTP request timeouts:
{
"version": "2.0",
"http": {
"routePrefix": "api"
},
"extensions": {
"http": {
"maxOutstandingRequests": 100,
"batchSize": 20,
"maxConcurrentRequests": 50
}
},
"logging": {
"logLevel": {
"default": "Information"
}
}
}
Deployment Slots
When using deployment slots, settings can be marked as "sticky" to remain with a specific slot during swaps, or they can be swapped along with the code. This allows for careful management of environment-specific configurations.
Common Settings
Setting Name | Description | Example Value |
---|---|---|
AzureWebJobsStorage |
Primary storage account for the Functions runtime. Required for most triggers. | DefaultEndpointsProtocol=https;AccountName=mystorage;AccountKey=...;EndpointSuffix=core.windows.net |
WEBSITE_CONTENTAZUREFILECONNECTIONSTRING |
Connection string for Azure Files, used for function content storage. | DefaultEndpointsProtocol=https;AccountName=mystorage;AccountKey=...;EndpointSuffix=core.windows.net |
FUNCTIONS_WORKER_RUNTIME |
Specifies the language runtime for your functions (e.g., dotnet , node , python , java ). |
node |
APPINSIGHTS_INSTRUMENTATIONKEY |
Instrumentation key for Azure Application Insights. | 00000000-0000-0000-0000-000000000000 |