Write message to another queue from queue trigger function app

Thomas Murnane 61 Reputation points
2023-03-14T19:42:40.6466667+00:00

I have a PowerShell function app that has a queue trigger that Invokes a run command on an Azure Vm. I'd like to write a message to a different queue same storage account from the function once the invoke command completes.

Is this possible to do? The goal is to send an email to the user who copied the file to let them know when the file is copied to the VM.

This is the code I'm running:

##################################################
# Web App writes to a 'fileUploaded' to queue 
#  this trigger when a file is copied to azure storage
##################################################

# Input bindings are passed in via param block.
param($QueueItem, $TriggerMetadata)

try 
{
   $FileName = $QueueItem['FileName']
   $PDB = $QueueItem['PDB']
   $EmailAddress = $QueueItem['EmailAddress']

   $StorageAccount = 'https://STORAGEACCOUNT.blob.core.windows.net/CONTAINER/'  
   $BlobURI = "{0}{1}" -f $StorageAccount, $FileName
   $ScriptPath = "F:\azCopy\CopyToDump.ps1"

   # Append arguments directly to the script path for a positional argument passing
   $ScriptFile = "$ScriptPath $PDB $FileName $BlobURI $EmailAddress"

   # Create a the actual script-to-run as a new PS script
   Out-File -InputObject $ScriptFile -FilePath .\ScriptToRun.ps1
 
   Invoke-AzVMRunCommand `
     -ResourceGroupName 'ciazuretst' `
     -VMName 'oracle-win-vm' `
     -CommandId 'RunPowerShellScript' `
     -ScriptPath ScriptToRun.ps1

   Remove-Item -Path ScriptToRun.ps1

##################################################
# TODO:
##################################################
#  Would like to write to a 'fileCopied' queue
#    when Invoke-AzVmRunCommand has completed
##################################################

} catch {
   write-host "$_.Exception.Message"
}
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,118 questions
Azure Queue Storage
Azure Queue Storage
An Azure service that provides messaging queues in the cloud.
109 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,602 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Thomas Murnane 61 Reputation points
    2023-03-14T20:47:18.5233333+00:00

    Sorry - found the documentation for this - added the output binding to the function.json:

       function.json:
    
       {
          "type": "queue",
          "direction": "out",
          "name": "Msg",
          "queueName": "queuename",
          "connection": "AzureWebJobsStorage"
        }
    Then just Push the message to the binding "name" Msg in run.ps1:
    
    Push-OutputBinding -Name Msg -Value $message
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.