Azurite doesn't work with Blob Trigger in VS Code

1.2k Views Asked by At

I have created a function to run locally, I am able to do it for HTTP Triggered functions, but when it comes to BlobTriggered I am always getting the same error.

I am using Azurite for mocking the Blob Service in Azure at the http://127.0.0.1:10000 endpoint The code I have is as follows:

local.settings.json

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

The C sharp code is as follows:

using System;
using System.IO;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;

namespace Company.Function
{
    public static class BlobTriggerCSharp1
    {
        [FunctionName("BlobTriggerCSharp1")]
        public static void Run([BlobTrigger("samples-workitems/{name}", Connection = "AzureWebJobsStorage")]Stream myBlob, string name, ILogger log)
        {
            log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
        }
    }
}

I am trying to create the new file on the Microsoft File Azure Storage on the container:

local-emulator -> Blob Containers -> samples-workitems -> create a new item

So always when I run after sometime I get the error bellow: Functions:

        BlobTriggerCSharp1: blobTrigger

For detailed output, run func with --verbose flag.
[2021-05-06T11:29:19.279Z] Host lock lease acquired by instance ID '000000000000000000000000182E0241'.   
[2021-05-06T11:29:47.002Z] An unhandled exception has occurred. Host is shutting down.
[2021-05-06T11:29:47.003Z] Microsoft.WindowsAzure.Storage: No connection could be made because the target machine actively refused it. System.Net.Http: No connection could be made because the target machine actively refused it. System.Private.CoreLib: No connection could be made because the target machine actively refused it.

EDIT

When I have tried to access the local storage account using Azurite from a local Azure Function

        var connection = new 

Uri("http://127.0.0.1:10000/devstoreaccount1/test123");

try {
            BlobContainerClient client = new BlobContainerClient(connection,
                                                 new DefaultAzureCredential());

            await foreach (BlobItem blobItem in client.GetBlobsAsync())
            {
                Console.WriteLine("\t" + blobItem.Name);
            }

When callnig client.GetBlobAsync I get the error:

"Cannot use TokenCredential without HTTPS."

EDIT2

The way I did that made it work was by following this tutorial: https://blog.jongallant.com/2020/04/local-azure-storage-development-with-azurite-azuresdks-storage-explorer/

But I wasn't able to setup the Azurite extension of Visual Studio Code to work with it. I needed to do it in a separate command line and needed to do it through https.

0

There are 0 best solutions below