I've been having some issues with my Azure Function that monitors a blob storage. I've followed the tutorial here: https://learn.microsoft.com/en-us/azure/azure-functions/functions-event-grid-blob-trigger?pivots=programming-language-csharp
I have my Azure Function setup, my event grid webhook setup and my blob storage ready. In application insights, I can see no errors for my app:
Then monitoring the event grid, I can see the uploads are triggered.
However, my Azure Function never triggers. I'm using the template code Visual Studio Code provides, the function also works fine when running locally.
Any suggestions on what I'm perhaps doing wrong, or someone that can point me in the right direction?
** UPDATE:
I've run the function locally too and set the webhook to route via ngrok. It runs as expected. So it does seem the issue seem to be the webhook receiving the information or the running of the Azure Function.
There is nothing or no errors on the logs at all. I'm not sure what else to do here. Any guidance on debugging would be appreciated.
My code looks as follows:
using System.IO;
using System.Threading.Tasks;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Logging;
namespace initroot.io
{
public class XXX
{
private readonly ILogger<XXX> _logger;
public XXXX(ILogger<XXX> logger)
{
_logger = logger;
}
[Function(nameof(XXXX))]
public async Task Run([BlobTrigger("XXXX/{name}", Source = BlobTriggerSource.EventGrid, Connection = "420bee_STORAGE")] Stream stream, string name)
{
using var blobStreamReader = new StreamReader(stream);
var content = await blobStreamReader.ReadToEndAsync();
_logger.LogInformation($"C# Blob Trigger (using Event Grid) processed blob\n Name: {name} \n Data: {content}");
}
}
}
When looking into the Azure Metric, I can see that each time I upload a new file, an instance is started for the Azure Function, indicating that the webhook is working. However, it seems the execution just never happens, or no output.
Initially, I was also getting same issue. In this case while adding the type of blob events in event grid subscription blob trigger is not available.
For getting the same requirement I have created event grid trigger function with runtime stack .NET 8.0 isolated.
Function code:
using System;
using Azure.Messaging.EventGrid;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Logging;
namespace Company.Function
{
public class EventGridTrigger1
{
private readonly ILogger<EventGridTrigger1> _logger;
public EventGridTrigger1(ILogger<EventGridTrigger1> logger)
{
_logger = logger;
}
[Function(nameof(EventGridTrigger1))]
public void Run([EventGridTrigger] EventGridEvent eventGridEvent)
{
_logger.LogInformation("Event type: {type}, Event subject: {subject}", eventGridEvent.EventType, eventGridEvent.Subject);
// Optional: Deserialize event data if needed
var data = eventGridEvent.Data.ToString();
_logger.LogInformation($"Event Data: {data}");
}
}
}
I have deployed the function into azure portal successfully.
storage events
.When i uploaded or deleted the blobs in container function got triggered successfully. check below:
Event grid output:
Function output: