azure-functionsazure-storage-explorerazurite

How to use Azurite blob containers as Azure Function internal storage and as trigger?


I've followed the instructions to download and install Azurite for Linux (Ubuntu 18.04). I want to use it with Azure Storage Explorer (also downloaded and installed) to visually manage/test an Azure Function with BlobTrigger. I understand how to start Azurite and can upload blobs to an emulator container using Storage Exporer.

Cannot figure out:

  1. How to connect an Azure Function to an Azurite container to use as the Functions internal storage.

    a. I used "AzureWebJobsStorage": "UseDevelopmentStorage=true" in local.settings.json, but I don't see how that connects the Function to a given container in Azurite

  2. How to connect the Function to an Azurite container for BlobTrigger functionality.

    a. Do I need to add a "BlobTrigger": "<azuriteContainerConnectionString>" setting to local.settings.json?


Solution

  • Basically, The Values in local.settings.json is been used to save the environment variable.

    The connection string is been declared in function.json. If you are using some language like C# or Java(Languages that need to be compiled, not run directly.), then it always have a declaration part, the declaration part will be convent to function.json after compiled.

    I start a Azurite on local, and I try to use the default storage account:

    I get the default connection string of blob service:

    DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;
    

    And I create a C# azure function with blobtrigger:

    local.settings.json

    {
        "IsEncrypted": false,
      "Values": {
        "AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=0730bowmanwindow;AccountKey=xxxxxx==;EndpointSuffix=core.windows.net",
        "FUNCTIONS_WORKER_RUNTIME": "dotnet",
        "str": "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;"
      }
    }
    

    Function1.cs

    using System;
    using System.IO;
    using Microsoft.Azure.WebJobs;
    using Microsoft.Azure.WebJobs.Host;
    using Microsoft.Extensions.Logging;
    
    namespace FunctionApp1
    {
        public static class Function1
        {
            [FunctionName("Function1")]
            public static void Run([BlobTrigger("test/{name}", Connection = "str")]Stream myBlob, string name, ILogger log)
            {
                log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
            }
        }
    }
    

    It seems works fine:

    enter image description here

    I set AzureWebJobsStorage to a storage on azure because 10000 port is been used.

    This is the doc:

    https://learn.microsoft.com/en-us/azure/storage/common/storage-use-azurite?toc=/azure/storage/blobs/toc.json