App Settings for Azure Functions
App settings in Azure Functions are key-value pairs that configure your function app. They are critical for managing your application's behavior, connecting to other services, and storing sensitive information.
App settings are available to your function code as environment variables. This document outlines the common app settings and how to configure them.
Common App Settings
- AzureWebJobsStorage: This is a required setting that the Functions runtime uses for various operational tasks, including managing triggers and logging. It must point to an Azure Storage account.
- WEBSITE_CONTENTAZUREFILECONNECTIONSTRING: For Linux Consumption and Premium plans, this setting provides the connection string to the storage account used for the function app's code.
- WEBSITE_HEALTHCHECK_MAXPINGFAILURES: Controls how many failed health check pings are allowed before the app is considered unhealthy.
- AzureFunctionsJobHost__
: Settings prefixed with this are passed directly to the Functions Host. For example,AzureFunctionsJobHost__extensions__=trueenables extension management. _STORAGE: For certain deployment scenarios, especially with older templates, a storage account might be specified this way.
Environment Variables
All app settings are exposed as environment variables within your function execution context. You can access them in your code:
Example (C#):
string storageConnectionString = Environment.GetEnvironmentVariable("AzureWebJobsStorage");
if (!string.IsNullOrEmpty(storageConnectionString))
{
// Use the connection string
}
Example (JavaScript):
const storageConnectionString = process.env.AzureWebJobsStorage;
if (storageConnectionString) {
// Use the connection string
}
Managing App Settings
You can manage app settings through the Azure portal, Azure CLI, or programmatically.
Azure Portal
- Navigate to your Function App in the Azure portal.
- Under Settings, select Configuration.
- Go to the Application settings tab.
- Add or edit your key-value pairs.
- Click Save.
Azure CLI
Use the az functionapp config appsettings set command:
az functionapp config appsettings set --name <YourFunctionAppName> --resource-group <YourResourceGroup> --settings AzureWebJobsStorage="<YourStorageConnectionString>"
Best Practices
Security Note: Never hardcode sensitive information like connection strings or API keys directly in your code. Use app settings or Azure Key Vault for secure storage and retrieval.
- Use App Settings for Configuration: Externalize configuration values like database connection strings, API endpoints, and feature flags.
- Secrets Management: For highly sensitive data, integrate with Azure Key Vault to store and manage secrets.
- Naming Conventions: Use clear and consistent naming conventions for your app settings.
- Environment-Specific Settings: Leverage different app settings for different deployment environments (development, staging, production).