【问题标题】:how can i access a blob from Azure Function (powershell) with an event grid trigger?如何使用事件网格触发器从 Azure Function (powershell) 访问 blob?
【发布时间】:2021-06-01 15:33:46
【问题描述】:

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

目前该函数什么都不做,因为我正在尝试处理下面的问题。

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

我尝试在我的函数的集成选项卡下添加一个 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

函数.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"
    }
  ]
}

【问题讨论】:

    标签: powershell azure-functions azure-eventgrid


    【解决方案1】:

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

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

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

    【讨论】:

      【解决方案2】:

      对于您对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。

      【讨论】:

        猜你喜欢
        • 2018-03-17
        • 1970-01-01
        • 2023-01-25
        • 2021-12-10
        • 2021-10-21
        • 1970-01-01
        • 2019-01-26
        • 2018-03-17
        • 2021-03-08
        相关资源
        最近更新 更多