Reputation: 51
I've gone through similar questions but I still can't understand why my Storage Queue Triggered Powershell Function isn't firing.
I have a function in my Function App that throws a message on a storage queue:
$AzStorageContext = New-AzStorageContext -ConnectionString $env:AzureWebJobsStorage
$Queue = Get-AzStorageQueue -Name "cichangedqueue" -Context $AzStorageContext
[Void]($Queue.QueueClient.SendMessage($JSON)
That works perfectly. I can see my messages appearing in the Queue.
I also have another function inside that same Function App with the following files:
{
"bindings": [
{
"name": "QueueItem",
"type": "queueTrigger",
"direction": "in",
"queueName": "cichangedqueue",
"connection": "AzureWebJobsStorage"
}
],
"scriptFile": "CiChangedHandler.ps1"
}
# Input bindings are passed in via param block.
param($QueueItem, $TriggerMetadata)
# Write out the queue message and insertion time to the information log.
Write-Host "PowerShell queue trigger function processed work item: $QueueItem"
Write-Host "Queue item insertion time: $($TriggerMetadata.InsertionTime)"
This is where it goes wrong.
According to Application Insights, the function isn't being triggered and I don't see anything in the logs but the messages all get transfered to cichangedqueue-poison. When I disable this function, they are not transferred to cichangedqueue-poison so it's this function that is trying to do something with those messages.
I also tried using the default run.ps1 filename and ditch the 'scriptFile' setting in function.json but that didn't change anything.
The environment variable AzureWebJobsStorage contains the connection string to the storage account that's being used for that function app.
any ideas on how to go forward with this?
{
"version": "2.0",
"managedDependency": {
"Enabled": true
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[4.*, 5.0.0)"
},
"concurrency": {
"dynamicConcurrencyEnabled": true,
"snapshotPersistenceEnabled": true
}
}
# This file enables modules to be automatically managed by the Functions service.
# See https://aka.ms/functionsmanageddependency for additional information.
#
@{
# For latest supported version, go to 'https://www.powershellgallery.com/packages/Az'.
# To use the Az module in your function app, please uncomment the line below.
'Az.AppConfiguration' = '1.*'
'Az.ManagedServiceIdentity' = '1.*'
'Az.OperationalInsights' = '3.*'
'Az.KeyVault' = '5.*'
'Az.Storage' = '5.*'
'Microsoft.Graph.Users' = '2.*'
'Microsoft.Graph.Authentication' = '2.*'
}
Of course this contains the correct SubscriptionId
# Azure Functions profile.ps1
#
# This profile.ps1 will get executed every "cold start" of your Function App.
# "cold start" occurs when:
#
# * A Function App starts up for the very first time
# * A Function App starts up after being de-allocated due to inactivity
#
# You can define helper functions, run commands, or specify environment variables
# NOTE: any variables defined that are not environment variables will get reset after the first execution
# Authenticate with Azure PowerShell using MSI.
# Remove this if you are not planning on using MSI or Azure PowerShell.
if ($env:MSI_SECRET) {
Disable-AzContextAutosave -Scope Process | Out-Null
Connect-AzAccount -Identity
#Connect-MgGraph -Identity
Set-AzContext -Subscription "00000000-1234-1234-1234-123412341234"
}
# Uncomment the next line to enable legacy AzureRm alias in Azure PowerShell.
# Enable-AzureRmAlias
# You can also define functions or aliases that can be referenced in any of your PowerShell functions.
Upvotes: 0
Views: 172
Reputation: 51
The issue was with the data I sent to the queue. Everything worked once I sent it Base64 encoded.
# Plaintext Message
$Message = [String]($($Body | ConvertTo-Json -Depth 15 -Compress))
# Convert message to Base64
$Bytes = [System.Text.Encoding]::UTF8.GetBytes($Message)
$Base64message = [System.convert]::ToBase64String($Bytes)
# Add messages to queue
[Void]($Queue.QueueClient.SendMessage($base64message))
Upvotes: 0