我正在使用Ubuntu 16.04.5 LTS本地计算机使用CLI和Azure功能核心工具(Ref)创建和发布Python功能应用程序到Azure。我已经配置了Blob Trigger,我的function.json文件如下所示:
{
"disabled": false,
"scriptFile": "__init__.py",
"bindings": [
{
"name": "<Blob Trigger Name>",
"type": "blobTrigger",
"direction": "in",
"path": "<Blob Container Name>/{name}",
"connection": "<Connection String having storage account and key>"
},
{
"name": "outputblob",
"type": "blob",
"path": "<Blob Container Name>",
"connection": "<Connection String having storage account and key>",
"direction": "out"
}
]
}
我的init.py函数看起来像这样。
def main(<Blob Trigger Name>: func.InputStream, doc: func.Out[func.Document]):
logging.info(f"Python blob trigger function processed blob \n"
f"Name: {<Blob Trigger Name>.name}\n"
f"Blob Size: {<Blob Trigger Name>.length} bytes")
logging.basicConfig(filename='example.log',level=logging.DEBUG)
logging.debug('This message should go to the log file')
logging.info('So should this')
logging.warning('And this, too')
# Write text to the file.
file = open("QuickStart.txt", 'w')
file.write("Hello, World!")
file.close()
# Create the BlockBlockService that is used to call the Blob service for the storage account
block_blob_service = BlockBlobService(account_name='<Storage Account Name>', account_key='<Storage Account Key>')
container_name='<Blob Container Name>'
# Set the permission so the blobs are public.
block_blob_service.set_container_acl(container_name, public_access=PublicAccess.Container)
# Upload the created file, use local_file_name for the blob name
block_blob_service.create_blob_from_path(container_name, 'QuickStart.txt', '')
功能应用程序是“始终打开”,但是当我在存储中上载blob时,该功能不会被触发。另一个参考链接是这个(Ref).
出了什么问题?
谢谢和问候,Shashank
您是否检查过local.settings.json
(存储帐户的连接字符串)是否也在Azure的功能应用程序中?默认情况下,它们不会从本地计算机发布。
您可以在门户中手动配置它们或使用publish-local-settings标志:
func azure functionapp publish "functionname" --publish-local-settings
我试图通过使用带有默认模板的Visual Studio代码在python中创建一个示例函数应用程序并最终部署在Linux中来重现此问题。它对我有用。
这是我在python文件中编写的代码片段。
import logging
import azure.functions as func
def main(myblob: func.InputStream):
logging.info(f"Python blob trigger function processed blob \n"
f"Name: {myblob.name}\n"
f"Blob Size: {myblob.length} bytes")
这是我的功能应用程序中的function.json文件。
{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "myblob",
"type": "blobTrigger",
"direction": "in",
"path": "samples-workitems/{name}",
"connection": ""
}
]
}
我使用2.0 Azure功能,python 3.6和Azure功能核心工具版本2.2.70
这是我使用的参考链接:
https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-first-function-python
请尝试使用它,看看它是否有帮助。