Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Prepare applications for Azure deployment by generating infrastructure code, Dockerfiles, and config files.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/services/functions/aspire-containerapps.md
1# Azure Functions on Azure Container Apps (Aspire)23When .NET Aspire deploys Azure Functions via `azd`, Functions run as containerized workloads on Azure Container Apps. **File-based secret storage is required** when using identity-based storage access.45> ⚠️ **Critical:** When Azure Functions use identity-based storage (e.g., `AzureWebJobsStorage__blobServiceUri`), you **must** set `AzureWebJobsSecretStorageType=Files`.67## Proactive Configuration in AppHost89**Best Practice:** Add this setting in your AppHost BEFORE running `azd up`:1011```csharp12var functions = builder.AddAzureFunctionsProject<Projects.Functions>("functions")13.WithHostStorage(storage)14.WithEnvironment("AzureWebJobsSecretStorageType", "Files") // Required for Container Apps15// ... other configuration16```1718This ensures the environment variable is automatically included in the generated infrastructure.1920## Container Apps Bicep Configuration2122When Aspire generates infrastructure, the Functions container app should include this environment variable. If you need to customize the generated Bicep or create it manually, the configuration looks like this:2324> **Note:** This example shows partial configuration. Assumes `containerAppEnv`, `storageAccount`, and `appInsights` resources are defined elsewhere in your Bicep templates.2526```bicep27resource functionsContainerApp 'Microsoft.App/containerApps@2024-03-01' = {28name: '${resourcePrefix}-${serviceName}-${uniqueHash}'29location: location30identity: {31type: 'SystemAssigned'32}33properties: {34environmentId: containerAppEnv.id35configuration: {36ingress: {37external: true38targetPort: 808039}40}41template: {42containers: [43{44name: 'functions-app'45image: containerImage46env: [47{48name: 'AzureWebJobsStorage__blobServiceUri'49value: storageAccount.properties.primaryEndpoints.blob50}51{52name: 'AzureWebJobsSecretStorageType'53value: 'Files' // Required for Container Apps with identity-based storage54}55{56name: 'APPLICATIONINSIGHTS_CONNECTION_STRING'57value: appInsights.properties.ConnectionString58}59{60name: 'FUNCTIONS_EXTENSION_VERSION'61value: '~4'62}63{64name: 'FUNCTIONS_WORKER_RUNTIME'65value: 'dotnet-isolated'66}67]68}69]70}71}72}73```7475## Why This Is Required7677- Identity-based storage URIs (e.g., `AzureWebJobsStorage__blobServiceUri`) work for runtime operations78- However, Functions' internal secret/key management does not support these identity-based URIs79- File-based secret storage is mandatory for Container Apps deployments with identity-based storage8081## Common Error Without This Setting8283```84System.InvalidOperationException: Secret initialization from Blob storage failed due to missing both85an Azure Storage connection string and a SAS connection uri.86```8788## When to Use This Configuration8990- Deploying Azure Functions to Container Apps via .NET Aspire91- Using `AddAzureFunctionsProject` with `WithHostStorage` in your AppHost92- Using identity-based storage access (no connection strings)93- Setting environment variables like `AzureWebJobsStorage__blobServiceUri`94