
Introduction
Is it possible to write data to the storage table when the Azure Event Grid trigger is invoked? Yes, it is possible. A colleague requested to log the output of the Azure Functions transactions to the Azure table storage, and my call is to store only the required data. Indeed, cost and readability is the primary concern. With no further ado, let me walk you through the requirement.
Challenge
A colleague tried to implement and reached out to me with a challenge. He claimed that it’s not possible to choose a different storage account to store the logs, and the evidence he shared is below

Event-Grid-Image-01
Oh well, it’s not a challenge, but it’s a limitation. You have no choice to provide an alternate storage account. Is it true? Let us figure it out! Refer to this documentation.

Connection
First, create an entry in the application settings and name it AzureWebJobsSTG01 and check the function integration. I hope it’s clear now!

Event-Grid-Image-02
Solution
Event Grid Trigger Code - Output binding
{
"bindings": [
{
"type": "eventGridTrigger",
"name": "eventGridEvent",
"direction": "in"
},
{
"name": "outputTable",
"tableName": "outTable",
"connection": "AzureWebJobsSTGLOGS",
"direction": "out",
"type": "table"
}
]
}
Event Grid Code - PowerShell Script
param($eventGridEvent, $TriggerMetadata)
$Result = $eventGridEvent | ConvertTo-Json | ConvertFrom-Json
Push-OutputBinding -Name outputTable -Value @{
PartitionKey = 'Test'
RowKey = $(New-Guid).Guid
Topic = $($Result.topic)
Subject = $($Result.subject)
EventTime = $($Result.eventTime)
EventType = $($Result.eventType)
}
Output

Share this post
Twitter
Google+
Facebook
Reddit
LinkedIn
StumbleUpon
Pinterest
Email