1
votes

Use Case:

I've an Azure Function that will be triggered by 'serviceBusTrigger'. Following best practices, I've the Azure service bus connection string in 'appsettings.json' and likewise in app-settings on the Azure function app. All is well!

Now, I want to run the function locally and I am using cli like

cd "my function folder path"

func run .\myfunction.cs

Issue

It starts but gives an error

'Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.someFunction'. Microsoft.Azure.WebJobs.ServiceBus: Microsoft Azure WebJobs SDK ServiceBus connection string 'AzureWebJobsServiceBusConnectionString' is missing or empty.'

Questions

1) Is is possible to keep my setup and be able to launch the function via 'cli' 2) how do i resolve this error side note: I understand that Azure function is build on top of webJob SDK and this error is bit cryptic.

Attached image shows the setup for function, function.json, appsettings.json

enter image description here

Thank you for your help!

1

1 Answers

2
votes

I'm noticing a couple of issues with the image you've shared:

Connection strings would typically go in the connection strings object of your app settings file, for example:

{
  "IsEncrypted": false,
  "Values": {
    "appsetting1": "test"
  },
  "ConnectionStrings": {
    "SomeConnectionString": "connectionstring"
  }
}

The function.jsonis invalid. Your bindings should be an array, like:

{
    "bindings": [
        {
             ... ....
            "connection": "ConnectionName"
             ... ....
        }
    ]
}

You cannot just point to a cs file to run the function. You're still expected to have the following structure when running your function:

 root
  |
  +-- functionname
  |   |-- function.json
  |   \-- run.csx (if working with the CSX model/just code)
  |
  +-- host.json
  +-- local.settings.json

From the root, you can then invoke the function using func run <functionname> where functionname maps to the folder name.

The file name shouldn't be an issue, but rename it to local.settings.json as it has changed.

You may also want to take a look at the Azure Functions Tools for Visual Studio 2017, as the will take care of all the setup for you and still allow you to run from the command like with the created structured, using the CLI, if you wish.