问题描述
我正在尝试设置在 blob 存储容器中创建文件时触发的 Powershell Azure 函数。该函数需要处理 blob 文件并将其保存到不同的 blob 存储容器中。
目前该函数什么都不做,因为我正在尝试处理下面的问题。
我无法从 powershell 函数内部访问 blob。我能够使用属性在 c# 中实现这一点,但似乎 powershell 不支持属性。
我尝试在我的函数的集成选项卡下添加一个 Azure Blob 存储输入,路径为“容器名称/{名称}”。但这只会导致错误:“命名参数'name'没有值。”
如何使用事件网格触发器从 powershell 函数访问 blob?
谢谢!
功能:
param($eventGridEvent,$TriggerMetadata,$inputBlob)
$fileName = $TriggerMetadata.Name;
Write-Host "file name: $($fileName)";
Push-OutputBinding -Name outputBlob -Value $fileName
function.json
{
"bindings": [
{
"type": "eventGridTrigger","name": "eventGridEvent","direction": "in"
},{
"name": "outputBlob","path": "https://storage01.blob.core.windows.net/container-name","connection": "Storage01ConnectionString","direction": "out","type": "blob"
},{
"name": "inputBlob","path": "container-name/{name}","direction": "in","type": "blob"
}
]
}
解决方法
对于 setup a Powershell Azure function that is triggered when a file is created in a blob storage container. The function needs to process the blob file and save it to a different blob storage container.
的要求,我认为您可以通过 blob 存储触发器并添加输出绑定(使用另一个 blob 存储容器)来完成。不需要事件网格触发器。
当在 samples-workitems
容器中创建了一个新文件时,它工作正常,然后将文件处理到输出容器 outcontainer
。
同一函数上不能有多个触发器(输入绑定),因此您需要选择一个:
- 或者只使用 blob 触发器(这是最简单的,但您可能会在创建 blob 和触发函数之间遇到高延迟);
- 或使用事件网格触发器,从事件中检索 blob 名称,然后使用 Az 模块检索 blob 内容(性能更高,但需要编写更多代码)。
重要的是每个函数只能有一个输入绑定。