如何使用Python使用Azure函数在BLOB容器中写入文本文件?
我正在尝试在Azure函数中运行一个计时器触发器,该计时器触发器将写入我的文件中,保存在blob存储容器output
AS log.txt
中。以下是我的 init .py-
import datetime
import logging
import azure.functions as func
def main(mytimer: func.TimerRequest, outputblob : func.Out[str]) -> None:
utc_timestamp = datetime.datetime.utcnow().replace(
tzinfo=datetime.timezone.utc).isoformat()
outputblob.set('some text')
if mytimer.past_due:
logging.info('The timer is past due!')
logging.info('Python timer trigger function ran at %s', utc_timestamp)
下面是function.json
的绑定 -
{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "mytimer",
"type": "timerTrigger",
"direction": "in",
"schedule": "0 */5 * * * *"
},
{
"name": "outputblob",
"type": "blob",
"dataType": "string",
"path": "output/log.txt",
"connection": "AzureWebJobsStorage",
"direction": "out"
}
]
}
该功能正在运行,但并未将任何内容写入log.txt
。我是Azure功能的初学者,所以请原谅愚蠢的错误。
I am trying to run a timer trigger in Azure function which will write into my file saved in the blob storage container output
as log.txt
. Below is my init.py -
import datetime
import logging
import azure.functions as func
def main(mytimer: func.TimerRequest, outputblob : func.Out[str]) -> None:
utc_timestamp = datetime.datetime.utcnow().replace(
tzinfo=datetime.timezone.utc).isoformat()
outputblob.set('some text')
if mytimer.past_due:
logging.info('The timer is past due!')
logging.info('Python timer trigger function ran at %s', utc_timestamp)
below are the bindings for function.json
-
{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "mytimer",
"type": "timerTrigger",
"direction": "in",
"schedule": "0 */5 * * * *"
},
{
"name": "outputblob",
"type": "blob",
"dataType": "string",
"path": "output/log.txt",
"connection": "AzureWebJobsStorage",
"direction": "out"
}
]
}
Also this is the output of the log stream which I checked today, maybe this could help
The function is running but it is not writing anything to the log.txt
. I am a beginner in the azure functions, so please pardon silly mistakes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从我们的末端繁殖后,这很好。确保您正在local.settings.json中添加存储帐户的连接字符串。同样,计时器功能中的玉米表达
0 */5 * * * * *
每小时运行12次,这意味着每5分钟都会发生触发器。因此,请确保等待直到函数触发。只是要检查结果是否得到反映,我将玉米表达式更改为
5-7 * * * * * *
每分钟运行3次。local.settings.json
结果:
更新答案
local.settings.json
函数。
下面是我的功能应用程序中的文件结构。
This was working fine after reproducing from our end. Make sure you are adding the connection string of your storage account in local.settings.json. Also the corn expression in your timer function
0 */5 * * * *
runs 12 times an hour which means for every 5 mins a trigger is going to occur. so make sure you wait until the function gets triggered.just to check if the result is getting reflected I have changed the corn expression to
5-7 * * * * *
which runs Three times a minute.local.settings.json
Results:
Updated Answer
local.settings.json
function.json
Below is the file structure in my Function App.