2
votes

Having a look through the documentation on azure functions, specifically this one. It's very clear how to setup integrations via the portal, but developing locally is very vague.

My code is structured below as follows:

[FunctionName("foobar")]
public static void Run([QueueTrigger("foo")]Foo myQueueItem, out object dbFoo)
{
  //do cool stuff here
}

The queue trigger works very well with the Azure storage emulator but there are no instructions on how to setup the local.settings.json. The file that was auto-generated via visual studio and looks like:

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

Where would the connection information for cosmos db sit within this structure to enable the function to operate correctly?

1

1 Answers

5
votes

It should look like this:

public static void Run(
    [QueueTrigger("foo")] Foo myQueueItem, 
    [DocumentDB("MyDB", "MyCollection", ConnectionStringSetting = "MyConnectionString")]
    out object dbFoo)

and the config would be:

{
    "IsEncrypted": false,
    "Values": {
        "MyConnectionString": "...your cosmos db string..."
    }
}

In Azure, you would have to put MyConnectionString parameter to App Settings.

Update: In V2 version of Functions DocumentDB binding attribute was replaced by CosmosDB attribute, see docs.