0

I installed Azurite and started ( assuming the command is correct.)

azurite --queueHost 127.0.0.1

I created an outqueue using Azure Storage Explorer

I want to test/use this function

const { app, output } = require('@azure/functions');

const queueOutput = output.storageQueue({
    queueName: 'outqueue',
    connection: 'MyStorageConnectionAppSetting',
});

app.http('httpTrigger1', {
    methods: ['GET', 'POST'],
    authLevel: 'anonymous',
    extraOutputs: [queueOutput],
    handler: async (request, context) => {
        const body = await request.text();
        context.extraOutputs.set(queueOutput, body);
        return { body: 'Created queue item.' };
    },
});

https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-queue-output?tabs=python-v2%2Cisolated-process%2Cnodejs-v4%2Cextensionv5&pivots=programming-language-javascript

What I dont know / understand is "MyStorageConnectionAppSetting" . (The name of an app setting or setting collection that specifies how to connect to Azure Queues. See Connections.)

Error

[2024-04-22T11:04:11.464Z] System.Private.CoreLib: Exception while executing function: Functions.httpTrigger1. Microsoft.Azure.WebJobs.Extensions.Storage.Queues: Storage account connection string 'AzureWebJobsMyStorageConnectionAppSetting' does not exist. Make sure that it is a defined App Setting.

what is the step I am missing to create that MyStorageConnectionAppSetting ? Any reference documentation that gives the steps is appreciated.

Thank you

0

1 Answer 1

0

To resolve the error, use the application setting "AzureWebJobsStorage": "UseDevelopmentStorage=true" in the local.settings.json to enable storage connection locally.

local.settings.json:

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

Change the Connection name in the function code.

Code Snippet:

const { app, output } = require('@azure/functions');

const queueOutput = output.storageQueue({
    queueName: 'outqueue',
    connection: 'AzureWebJobsStorage ',
});

app.http('httpTrigger1', {
    methods: ['GET', 'POST'],
    authLevel: 'anonymous',
    extraOutputs: [queueOutput],
    handler: async (request, context) => {
        const body = await request.text();
        context.extraOutputs.set(queueOutput, body);
        return { body: 'Created queue item.' };
    },
});

Run the function locally:

C:\Users\uname\function>func start

Azure Functions Core Tools
Core Tools Version:       4.0.5611 Commit hash: N/A +591b8aec842e333a87ea9e23ba390bb5effe0655 (64-bit)
Function Runtime Version: 4.31.1.22191

[2024-04-22T13:17:40.044Z] Worker process started and initialized.

Functions:

        httpTrigger1: [GET,POST] http://localhost:7071/api/httpTrigger1

For detailed output, run func with --verbose flag.
[2024-04-22T13:17:53.133Z] Executing 'Functions.httpTrigger1' (Reason='This function was programmatically called via the host APIs.', Id=00ec97ec-a464-43af-acff-854c28b43711)
[2024-04-22T13:17:56.667Z] Executed 'Functions.httpTrigger1' (Succeeded, Id=00ec97ec-a464-43af-acff-854c28b43711, Duration=3631ms)

Response:

enter image description here

Sign up to request clarification or add additional context in comments.

6 Comments

Looks promising. sorry I am a starter, I have a question about this - "MyStorageConnectionAppSetting":"<Storage_Connection_String>". From where can I get that information. I am using local environment azurite.
You can copy the connection string from Portal=>Azure Storage account=>Security+Networking=>Access leys=>Connection String.
How can I make use of local ? I presume you understood the goal, developing this locally.
You can use AzureWebJobsStorage instead of MyStorageConnectionAppSetting as value to the connection in the code.
I can accept answer, if you make this shorter. Because the simple answer is connection: "AzureWebJobsStorage", and local settings is "AzureWebJobsStorage": "UseDevelopmentStorage=true", for local emulator. Thanks
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.