Gary' Blog

Run/Debug Azure Function App with Local Storage Azurite

To archive this, you have to have VSCode installed in local machine.

Step 1: Install Azurite in VSCode

  1. Open VSCode Extensions and search Azurite, install it.
  2. Press F1, in command bar, search Azurite: Start, select it then the Azurite will start in your local machine.

Step 2: Install Microsoft Azure Storage Explorer

  1. Download Azure Storage Explorer.
  2. Install and Open it.
  3. Under Emulator & Attached -> Storage Accounts -> (Emulator - Default Port) (Key) -> Blob Containers, create a new container for testing.

Step3: Change local.settings.json

Change AzureWebJobsStorage value to UseDevelopmentStorage=true. As following:

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "python",
    "AzureWebJobsFeatureFlags": "EnableWorkerIndexing"
  }
}

Step 4: start up

Here is my code:

import azure.functions as func
import logging

app = func.FunctionApp()

@app.blob_trigger(arg_name="inputblob", path="input_container/{name}.pdf", connection="AzureWebJobsStorage")
@app.blob_output(arg_name="outputblob", path="output_container/{filename}.pdf.json", connection="AzureWebJobsStorage")
def blob_trigger(inputblob: func.InputStream, outputblob: func.Out[str]):
    logging.info(f"Python blob trigger function processed blob "
                f"Name: {inputblob.name} "
                f"Blob Size: {inputblob.length} bytes")
    outputblob.set(inputblob)

Step 5: Run

func start

Open Azure Storage Explorer and upload file. You will see the log in terminal.

Please remind the the arg_name can only be English letters and numbers, and NO underscore _ and other special charactars.

Exit mobile version