简体   繁体   中英

Function App Blob Trigger debugging in VS Code failed in Azurite

I have created a sample Blobtrigger Azure function and would like to debug it with Azurite in VScode. However it always throws the same error after a debugging session is started.

I am using Azurite for mocking the Blob Service in Azure.

Docker command:

docker run -p 10000:10000 -p 10001:10001 -p 10002:10002 mcr.microsoft.com/azure-storage/azurite

The code I have in the repository is as follows:

local.settings.json, with default connection string to Azurite

{"IsEncrypted": false,
 "Values": {
    "FUNCTIONS_WORKER_RUNTIME": "python",
    "AzureWebJobsStorage": "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;TableEndpoint=http://127.0.0.1:10002/devstoreaccount1;"
},

__init__.py

import logging

import azure.functions as func

def main(myblob: func.InputStream):
    logging.info(f"Python blob trigger function processed blob \n"
                 f"Name: {myblob.name}\n"
                 f"Blob Size: {myblob.length} bytes")

and function.json

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "name": "myblob",
      "type": "blobTrigger",
      "direction": "in",
      "path": "cleansed-zone/{name}",
      "connection": "AzureWebJobsStorage"
    }
  ]
}

After clicking run and debug in VSCode, an exception is always thrown.

 Azure.Core: An error occurred while sending the request.

Due to some environment constraints, I could not set up HTTPS on Azurite Docker and not yet able to verify what is the root cause of the error.

Any working setup guidelines for Azurite and Function App local projects would be appreciated.

Edit: Replace the connectionstring to a Cloud storage account on Azure runs without any issue. Storage explorer also works fine when uploading sample files to Azurite. However docker keep throwing multiple 404 errors when debugging, and failed to create some blob/queues/tables which are compulsory for function apps

172.17.0.1 - - [19/Jan/2022:11:22:53 +0000] "HEAD /devstoreaccount1/azure-webjobs-blobtrigger-lex10242-1234567890?comp=metadata HTTP/1.1" 404 
172.17.0.1 - - [19/Jan/2022:12:47:49 +0000] "PUT /devstoreaccount1/azure-webjobs-hosts/locks/lez10242-1234567890/WebJobs.Internal.Blobs.Listener?comp=lease HTTP/1.1" 404 -

We have tried in our local to use Azurite and it works as expected.

To do that installed following perquisite in our local:

Docker (Docker Installation for Windows, Docker Installation for Linux )

Azure Storage Explorer

Azure Functions Core Tools

Python Once the complete setup is done make sure you have added the following in your local settings.json

{
  "IsEncrypted": false,
  "Values": {
    "FUNCTIONS_WORKER_RUNTIME": "python",
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "AzureWebJobsDashboard": "UseDevelopmentStorage=true",
    "QueueConnectionString": "AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;DefaultEndpointsProtocol=http;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;TableEndpoint=http://127.0.0.1:10002/devstoreaccount1;"
  }
}

And add the following in your function.json

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "name": "myblob",
      "type": "blobTrigger",
      "direction": "in",
      "path": "the container name which we created in storage explorer",
      "connection": ""
    }
  ]
}

Then run your application by using func start

Here is the OUTPUT for reference: 在此处输入图像描述

For complete setup please refer this BLOG

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM