简体   繁体   English

如何使用 python 3 编辑和保存 azure function 应用程序的配置环境变量?

[英]How can I edit and save configuration env variable of a azure function app using python 3?

I am working on a project where I have to edit and save azure function variable using python3 in a set of time period(Azure Timer Trigger).我正在开发一个项目,我必须在一组时间段(Azure Timer Trigger)中使用 python3 编辑和保存 azure function 变量。 I use this to get the env variable,我用它来获取环境变量,

import os
departmentid = str(os.getenv("departmentID"))

But it is able to get not to do any edit... and I got this also, https://docs.microsoft.com/en-us/azure/azure-app-configuration/quickstart-python#update-a-configuration-setting但它可以不做任何编辑......我也得到了这个, https://docs.microsoft.com/en-us/azure/azure-app-configuration/quickstart-python#update-a-配置设置

But it is working in Azure App Config not in Azure App Function.但它在 Azure 应用程序配置中工作,而不是在 Azure 应用程序 Function 中工作。 Can anyone suggest a solution to edit and save new value to particualr env keys using python3?任何人都可以建议使用python3编辑和保存新值到特定环境键的解决方案吗?

Environment Variables are configured for the Function App in Azure Functions from portal and can be accessible by all functions within that app.环境变量是为 Azure 功能中的 Function 应用程序配置的,并且可以通过该应用程序中的所有功能访问。 They are set from the 'Configuration' tab of the left pane's Settings.它们是从左窗格设置的“配置”选项卡中设置的。

Function App 中的应用程序设置

Provide a name and a value of your variable to add your own application setting by clicking on New application setting and Then click on 'Save'.提供变量的名称和值以添加您自己的应用程序设置,方法是单击New application setting ,然后单击“保存”。

添加应用程序设置

保存设置

and then try the below code within your function code to access the environment variable.然后在您的 function 代码中尝试以下代码来访问环境变量。

import os new_db_flag = int(os.environ["NEW_DB_FLAG"])

To edit the same you can navigate to the configurations page -> click on the variable that you wanted to change -> edit the value of it and click save.要编辑相同的内容,您可以导航到配置页面 -> 单击要更改的变量 -> 编辑它的值并单击保存。

NOTE: If your Function app runs on Consumption plan then it allows only one deployment slot .注意:如果您的 Function 应用程序在消费计划上运行,则它只允许一个部署槽

REFERENCES: How to set Environment Variables in Azure Functions参考: 如何在 Azure 函数中设置环境变量

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM