Search code examples
azure-functionsazurite

azure function blog triggered eventgrid not firing using local storage development


I created a new azure function using vs 2022 community, using blob trigger event grid template. when I drop the file in azure storage explorer my function is not firing. If I goto the output window, under service dependencies, I do see the file that I dropped. however I added some breakpoints and its never getting hit.

does anyone see something wrong in my configuration?

    public class Function1
{
    private readonly ILogger<Function1> _logger;

    public Function1(ILogger<Function1> logger)
    {
        _logger = logger;
    }

    [Function(nameof(Function1))]
    public async Task Run([BlobTrigger("samples-workitems/{name}", Source = BlobTriggerSource.EventGrid, Connection = "AzureWebJobsStorage")] 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}");
    }
}

local.settings.json below

{
"IsEncrypted": false,
"Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
}

}

storage emulator

output window


Solution

  • You can try the same in Visual Studio Code as illustrated in MS documentation instead of Visual Studio.

    I believe executing a non Http trigger function by providing request body is not possible in visual studio alike visual studio code.

    In order to trigger the Blob trigger function with event grid template, first execute the function using func host start command in terminal or navigate to Run -> Start Debugging. You will get below response and keep it running.

    enter image description here

    Then, upload a file to the container created in local emulator. Once done, click Execute Function Now

    enter image description here

    This will prompt you to provide the container name and the file name which is present in it.

    enter image description here

    Upon Entering, your function will trigger.

    enter image description here