英文:
Why is my Azure Function stuck in read-only mode?
问题
我正在尝试将一小段Python代码部署到Azure云中。我想要创建一个函数,该函数会向一个API发送请求,处理响应,并将输出存储到Azure中的CSV文件中。它会从Azure Keyvault中存储和检索API密钥。
由于函数处于只读模式,无法创建所需的新CSV文件,因此我无法运行我的代码。
迄今为止,我已经完成了以下工作:
- 为资源创建了一个新的资源组。
- 创建了一个在Linux上运行的新函数应用程序,设置为Python运行时。
- 为函数应用程序创建了专用的应用服务计划和应用程序性能监视资源。
- 创建了一个KeyVault,并将API密钥存储为KV Secret。
- 为Azure函数创建了一个系统分配的托管标识,并创建了一组新的Keyvault策略,以允许函数访问“获取”KV密钥。
- 通过将Keyvault标识添加到函数的应用程序设置中,将Keyvault和函数关联起来。
- 在函数的应用程序设置中,将FUNCTION_APP_EDIT_MODE设置为“readwrite”。还将WEBSITE_RUN_FROM_PACKAGE设置为“0”(也尝试过设置为“1”,但没有成功)。
为了更好理解,我是使用VS Code中的Azure Functions扩展部署函数本身的。
如果有关如何允许写入新CSV文件的建议,或者任何在Azure中运行此代码的替代方法的建议,都将不胜感激。
编辑:问题是否实际上是代码未输出到附加的存储帐户?函数是只读的,可能并非真正的问题……
我的function.json
文件:
{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "mytimer",
"type": "timerTrigger",
"direction": "in",
"schedule": "0 0 4 * * *"
},
{
"name": "outputFile",
"direction": "out",
"type": "file",
"path": "output/csv",
"connection": "AzureWebJobsStorage"
}
]
}
我__init__.py
文件的一部分,试图将数据写入CSV文件并放置在存储中:
with open("non_exempt_devices.csv", "w", newline="") as f:
writer = csv.writer(f)
writer.writerow(["Host Name", "Metadata"])
writer.writerows(output[0])
outputFile.set(f)
英文:
I am attempting to deploy a small piece of python code to the Azure cloud. I want a function which makes a request to an API, manipulates the response, and puts the output into a CSV file all in Azure. It stores and retrieves the API keys from the Azure Keyvault.
I am unable to run my code as the Function is stuck in read-only mode, so it cannot create a new CSV file as is needed.
Here's what I've done so far:
- Created a new resource group for the resources.
- Created a new function app running on Linux. It is set to python runtime.
- Created dedicated App Service Plan and Application Insights resources for the function app.
- Created a KeyVault and stored the API keys as a KV Secret.
- Created a system assigned managed identity for the Azure Function, and created a new set of Keyvault policies to allow the Function access to 'get' KV secrets.
- Linked the Keyvault and Function by adding the Keyvault identity(?) to the Function's application settings.
- In the Function's application settings, set FUNCTION_APP_EDIT_MODE to 'readwrite'. Also set WEBSITE_RUN_FROM_PACKAGE to '0' (also tried this as '1' but to no avail).
For context, I am deploying the function itself using the Azure Functions extension in VS Code.
Any suggestions about how to allow the writing of a new CSV file would be appreciated. Alternatively, any suggestions for alternatives method to run this code in Azure would also be welcomed.
Edit: Could the problem here actually be that the code is not outputting to the attached storage account? That the function is read-only might not be the true problem here...
My function.json
file:
{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "mytimer",
"type": "timerTrigger",
"direction": "in",
"schedule": "0 0 4 * * *"
},
{
"name": "outputFile",
"direction": "out",
"type": "file",
"path": "output/csv",
"connection": "AzureWebJobsStorage"
}
]
}
A snippet of my __init__.py
file which attempts to write to a CSV file and place in storage:
with open("non_exempt_devices.csv", "w", newline="") as f:
writer = csv.writer(f)
writer.writerow(["Host Name", "Metadata"])
writer.writerows(output[0])
outputFile.set(f)
答案1
得分: 1
>为什么我的 Azure 函数处于只读模式?
- 当您首次部署函数应用(dll 文件)时,它将处于只读模式。
- 即使您删除或禁用应用设置
WEBSITE_RUN_FROM_PACKAGE
,直到下次发布带有一些更改的函数应用,只读模式才会消失。 - 您还可以发布 Azure Functions 项目而不使用 zip 文件来摆脱只读模式。
我知道您正在使用 VS Code,我们可以在 Visual Studio 中发布 Azure Functions 项目而不使用 zip,但在 VS Code 中无法做到。
然后,您可以使用此 Stack Overflow 答案 中提供的命令来在不使用 zip 的情况下部署/上传到函数应用。
英文:
>Why is my Azure Function stuck in read-only mode?
- When you deploy the function app (dll files) for the 1st time, it will be in read-only mode.
- Even you delete or disable the application setting
WEBSITE_RUN_FROM_PACKAGE
, until you publish the function app with some changes next time then read-only mode will not disappear. - You can also publish the Azure Functions project without zip to rid out of the read-only mode.
I know that you’re using the VS Code where we have the Publish the Azure Functions Project without zip in Visual Studio but not in VS Code.
Then you can make use of the command to deploy/upload without zip to the function app as given in this SO Answer.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论