I'm working on an Azure Functions project in Visual Studio and facing an issue with accessing application settings that are configured in Azure. I have set certain configuration values in the Azure portal under my Function App's application settings. However, I'm unable to access these settings in my local development environment.
Local Setup:
Issue:
When I run my function locally and attempt to access environment variables set in local.settings.json, they return empty. I've tried accessing the variables using the $env:VariableName syntax in PowerShell, but it doesn't seem to work.
Write-Host "Storage Account Connection String: $($env:klantacontainer)"
Write-Host "Test Variable: $($env:TestVariable)"
# In my run.ps1 file
$storageAccountConnectionString = $env:klantacontainer
Write-Host "Storage Account Connection String: $storageAccountConnectionString"
$testVariable = $env:TestVariable
Write-Host "Test Variable: $testVariable"
Attempts:
Application settings
I am able to get the values from local settings file using the code given below.
run.ps1-
using namespace System.Net
# Input bindings are passed in via param block.
param($Request, $TriggerMetadata)
# Write to the Azure Functions log stream.
Write-Host "PowerShell HTTP trigger function processed a request."
Write-Host "Test Variable: $($env:TestVariable)"
# Interact with query parameters or the body of the request.
$name = $Request.Query.Name
if (-not $name) {
$name = $Request.Body.Name
}
$body = "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
if ($name) {
$body = "Hello, $name. This HTTP triggered function executed successfully."
}
# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = $body
})
local.settings-
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "",
"FUNCTIONS_WORKER_RUNTIME_VERSION": "7.2",
"FUNCTIONS_WORKER_RUNTIME": "powershell",
"TestVariable": "TestValue"
}
}
host.json-
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[3.*, 4.0.0)"
},
"managedDependency": {
"enabled": true
}
}
I am able to get the value of TestVariable as shown below-