英文:
Azure function Application settings is not consistent to values in local.settings.json
问题
local.settings.json
文件中的内容如下:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "",
"FUNCTIONS_WORKER_RUNTIME": "node",
"WEBSITE_RUN_FROM_PACKAGE": 1,
"SCM_DO_BUILD_DURING_DEPLOYMENT": true
}
}
然而,在成功执行以下命令后:
$ npm run-script build && zip -r azure_function.zip . && az functionapp deployment source config-zip -g acmeapp -n acmefunction2 --src azure_function.zip
部署到Azure函数应用程序后。
但在Settings | Configuration | Application settings
中:
如下图所示:
正如您所看到的:
FUNCTIONS_WORKER_RUNTIME
被设置为"node",这是预期的。
WEBSITE_RUN_FROM_PACKAGE
被设置为0,为什么不是1?
SCM_DO_BUILD_DURING_DEPLOYMENT
被设置为false
,为什么?
英文:
local.settings.json
:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "",
"FUNCTIONS_WORKER_RUNTIME": "node",
"WEBSITE_RUN_FROM_PACKAGE": 1,
"SCM_DO_BUILD_DURING_DEPLOYMENT": true
}
}
However, after successfully executing:
$ npm run-script build && zip -r azure_function.zip . && az functionapp deployment source config-zip -g acmeapp -n acmefunction2 --src azure_function.zip
...
Getting scm site credentials for zip deployment
Starting zip deployment. This operation can take a while to complete ...
Deployment endpoint responded with status code 202
{
"active": true,
"author": "N/A",
"author_email": "N/A",
"complete": true,
"deployer": "Push-Deployer",
"end_time": "2023-08-08T16:22:50.8690074Z",
"id": "3cba98a7-a231-45b8-847a-f0222e38731c",
"is_readonly": true,
"is_temp": false,
"last_success_end_time": "2023-08-08T16:22:50.8690074Z",
"log_url": "https://acmefunction2.scm.azurewebsites.net/api/deployments/latest/log",
"message": "Created via a push deployment",
"progress": "",
"received_time": "2023-08-08T16:21:36.1656327Z",
"site_name": "acmefunction2",
"start_time": "2023-08-08T16:21:38.0518534Z",
"status": 4,
"status_text": "",
"url": "https://acmefunction2.scm.azurewebsites.net/api/deployments/latest"
}
The function is deployed to Azure function app.
But in Settings | Configuration | Application settings
:
As you can see:
FUNCTIONS_WORKER_RUNTIME
is set to "node", which is as expected.
WEBSITE_RUN_FROM_PACKAGE
is set to 0, why not 1?
SCM_DO_BUILD_DURING_DEPLOYMENT
is set to false
, why?
答案1
得分: 1
在Azure Functions中,local.settings.json
文件用于本地开发,不会在将函数部署到Azure时直接使用。相反,需要手动将local.settings.json
中的设置应用到Azure门户中的应用程序设置或通过Azure CLI等命令行工具进行设置。这种分离确保开发人员可以拥有本地设置,而不会覆盖生产环境的设置。
为了确保local.settings.json
中的设置反映在Azure函数应用中,可以使用Azure CLI进行设置:
az functionapp config appsettings set --name acmefunction2 --resource-group acmeapp --settings FUNCTIONS_WORKER_RUNTIME=node WEBSITE_RUN_FROM_PACKAGE=1 SCM_DO_BUILD_DURING_DEPLOYMENT=true
英文:
In Azure Functions, local.settings.json
file is meant for local development and isn't directly used when you deploy the function to Azure. Instead, the settings in local.settings.json
need to be manually applied to the Application Settings in the Azure portal or through command-line tools like the Azure CLI. This separation ensures that developers can have local settings that don't necessarily override the production settings.
To ensure your settings in local.settings.json
are reflected in the Azure Function App, you can use the Azure CLI to set them:
az functionapp config appsettings set --name acmefunction2 --resource-group acmeapp --settings FUNCTIONS_WORKER_RUNTIME=node WEBSITE_RUN_FROM_PACKAGE=1 SCM_DO_BUILD_DURING_DEPLOYMENT=true
答案2
得分: 0
请阅读此文档:https://learn.microsoft.com/zh-cn/azure/azure-functions/functions-run-local?tabs=linux%2Cportal%2Cv2%2Cbash&pivots=programming-language-typescript#project-file-deployment
使用-publish-local-settings
选项,根据local.settings.json文件中的值自动在函数应用中创建应用设置。
英文:
Use the -publish-local-settings
option to automatically create app settings in your function app based on values in the local.settings.json file.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论