Azure函数的应用程序设置与local.settings.json中的值不一致。

huangapple go评论74阅读模式
英文:

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中:

如下图所示:

Azure函数的应用程序设置与local.settings.json中的值不一致。

正如您所看到的:

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:

Azure函数的应用程序设置与local.settings.json中的值不一致。

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文件中的值自动在函数应用中创建应用设置。

英文:

Read this doc: https://learn.microsoft.com/en-us/azure/azure-functions/functions-run-local?tabs=linux%2Cportal%2Cv2%2Cbash&pivots=programming-language-typescript#project-file-deployment

Use the -publish-local-settings option to automatically create app settings in your function app based on values in the local.settings.json file.

huangapple
  • 本文由 发表于 2023年8月9日 00:47:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76861639.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定