[英]Azure Function Environment Variables
I'm trying to create a super basic Azure Function, but am having trouble with environment variables. 我正在尝试创建一个超基本的Azure函数,但是遇到了环境变量的麻烦。 Following various tutorials online, 遵循各种在线教程,
var config = new ConfigurationBuilder()
.SetBasePath(context.FunctionAppDirectory)
.AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
log.Info(config["AzureWebJobsStorage"]);
My local.settings.json looks like this: 我的local.settings.json看起来像这样:
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "<language worker>",
"AzureWebJobsStorage": "abc123",
"AzureWebJobsDashboard": "abc123",
"MyBindingConnection": "abc123"
},
"Host": {
"LocalHttpPort": 7071,
"CORS": "*"
}
}
When I run this locally, that 当我在本地运行时,
log.Info(config["AzureWebJobsStorage"]);
line returns nothing... but when I deploy to Azure I see "abc123" in the console. 行什么都没有返回...但是当我部署到Azure时,在控制台中看到“ abc123”。
If, however, I alter that line to 但是,如果我将该行更改为
log.Info(config["Values:AzureWebJobsStorage"]);
Then when I run locally, I see "abc123" but when I deploy to Azure I see nothing. 然后,当我在本地运行时,看到“ abc123”,但是当我部署到Azure时,什么也看不到。
Is there something I'm missing to be able to reach the environment variables the same way locally vs deployed? 我缺少能够以本地方式还是部署方式访问环境变量的东西吗?
EDIT: To clarify, these settings are configured in the app settings for the function: 编辑:为澄清起见,这些设置是在该功能的应用程序设置中配置的:
假设您正在使用〜2运行时作为Azure函数的目标,则可以通过以下方式访问配置值:
log.Info(Environment.GetEnvironmentVariable("AzureWebJobsStorage", EnvironmentVariableTarget.Process));
Those environmental variables work when you are testing your function locally. 在本地测试功能时,这些环境变量会起作用。 However, when you deploy to the Azure Function Portal, you need to setup your variables using their built-in system to handle Environmental Variables. 但是,当部署到Azure功能门户时,需要使用它们的内置系统来设置变量以处理环境变量。
Copy and past your key-values into the sections that I highlighted in the image below. 将键值复制并粘贴到下图中突出显示的部分中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.