6

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?

SeaDude
  • 3,725
  • 6
  • 31
  • 68

2 Answers2

6

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
Cindy Pau
  • 13,085
  • 1
  • 15
  • 27
  • This is helpful @BowmanZhu, thank you. I have port 10000 available, so I will use `"AzureWebJobsStorage": "UseDevelopmentStorage=true"`. Question remains: Do I need to create an Azurite container named `"AzureWebJobsStorage"` or will it create one automatically? – SeaDude Sep 21 '20 at 14:36
  • @SeaDude This is the storage used to store function related files. I'm not sure where you'll end up using it. As you are using the bloglogger, azurewebjobstorage must provide. As far as I know, the local default storage simulator's blob service uses port 10000, which coincides with azurite's default port. You may need to change one of the blob service ports. – Cindy Pau Sep 21 '20 at 14:42
  • @SeaDude Azurewebjobstorage involves some underlying things. It's not specific. You can use local or azure storage. You just need to give one. – Cindy Pau Sep 21 '20 at 14:45
  • @SeaDude You can change the port number used by azurite's blob service so that it does not conflict with the local default storage simulator. This is mentioned in the link I gave in the answer. "UseDevelopmentStorge=true" means using local default emulator. – Cindy Pau Sep 21 '20 at 14:50
  • I've got Azurite running and my function app connection to it but there is no container there to store anything in. How do you create a container in the Azurite blob storage? – HisDivineShadow Dec 10 '20 at 23:39
  • 1
    I'm sure this is too late to help @HisDivineShadow but to answer his question for future visitors, one of the easiest ways to administrate your Azurite emulator, as far as creating containers and uploading blobs, etc., is to use the Azure Storage Explorer. – brettbaggott Feb 05 '21 at 04:14
1

Using the Microsoft Azure Storage Explorer to manage queueing, the following settings will work.

(In this case the framework used was .net 5).

Its not particularly obvious but you must set the connection string to use the value "UseDevelopmentStorage=true"

My local.settings.json file after creating a new function enter image description here My function enter image description here

DisplayName
  • 196
  • 3
  • 12