如何使用事件网格触发器从 Azure Function (powershell) 访问 blob?

how can i access a blob from Azure Function (powershell) with an event grid trigger?

我正在尝试设置在 blob 存储容器中创建文件时触发的 Powershell Azure 函数。该函数需要对blob文件进行处理,并将其保存到不同的blob存储容器中。

目前函数没有任何作用,因为我正在尝试处理下面的问题。

我无法从 powershell 函数内部访问 blob。我能够在 c# 中使用属性实现这一点,但似乎 powershell 不支持属性。

我尝试在我的函数的集成选项卡下添加一个 Azure Blob 存储输入,路径为“container-name/{name}”。但这只会导致错误:“命名参数 '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}",
      "connection": "Storage01ConnectionString",
      "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 存储容器)来完成。不需要事件网格触发器。

下面是我的函数代码和function.json:

samples-workitems容器中创建新文件时工作正常,然后将文件处理到输出容器outcontainer

同一个函数不能有多个触发器(输入绑定),因此您需要选择一个:

  • 要么只使用 blob 触发器(这是最简单的,但您可能会在创建 blob 和触发函数之间遇到高延迟);
  • 或使用事件网格触发器,从事件中检索 blob 名称,并使用 Az 模块检索 blob 内容(性能更高,但需要编写的代码更多)。

重要的是每个函数只能有一个输入绑定。