1
votes

I am trying to 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.

At the moment the function does nothing, as i am trying to deal with the problem below.

I am having trouble accessing the blob from inside the powershell function. I was able to Achieve this in c# using Attributes, but it appears that Attributes are not supported in powershell.

I tried adding an Azure Blob Storage Input under the integration tab of my function, with the path "container-name/{name}". but this just causes the error: "No value for named parameter 'name'."

How can i access a blob from a powershell function with an event grid trigger?

Thanks!

function:

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"
    }
  ]
}
2

2 Answers

1
votes

For your requirement of 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. I think you can do it just by blob storage trigger and add an output binding(with another blob storage container). Event grid trigger is not necessary.

Below is my function code and function.json: enter image description here

enter image description here

It works fine when there is a new file created in samples-workitems container, then process the file to the output container outcontainer.

1
votes

You cannot have more than one trigger (input binding) on the same function, so you will need to choose one:

  • either use just the blob trigger (this is the simplest, but you may experience high latency between creating the blob and triggering the function);
  • or use the event grid trigger, retrieve the blob name from the event, and use the Az module to retrieve the blob content (more performant, but more code for you to write).

The important thing is you can have just one input binding per function.