I am writing an http trigger Azure function in F# and I would like to bind a parameter of type DocumentClient to have more control on the queries that are done in Cosmos DB. This is what I have so far:
Function.fs
namespace Functions
open System
open System.Net
open System.Net.Http
open Newtonsoft.Json
open Microsoft.Azure.Documents
open Microsoft.Azure.Documents.Client
open Microsoft.Azure.WebJobs
open Microsoft.Azure.WebJobs.Host
open Microsoft.Azure.WebJobs.Extensions
open Microsoft.Azure.WebJobs.Extensions.DocumentDB
module Function =
let Run(req: HttpRequestMessage, [<DocumentDB>] client: DocumentClient, log: TraceWriter) =
log.Info(sprintf "F# HTTP trigger function processed a request.")
req.CreateResponse(HttpStatusCode.OK)
function.json
{
"disabled": false,
"scriptFile": "..\\..\\..\\build\\Debug\\Functions\\Functions.dll",
"entryPoint": "Functions.Function.Run",
"bindings": [
{
"direction": "in",
"type": "httpTrigger",
"authLevel": "anonymous",
"name": "req",
"methods": [ "get" ],
"route": "users"
},
{
"direction": "in",
"type": "documentDB",
"name": "client",
"connection": "COSMOSDB_CONNECTION_STRING"
},
{
"direction": "out",
"type": "http",
"name": "res"
}
]
}
host.json
{
"frameworks": {
"net46":{
"dependencies": {
"Dynamitey": "1.0.2",
"FSharp.Interop.Dynamic": "3.0.0",
"Microsoft.Azure.DocumentDB": "1.17.0",
"Microsoft.Azure.WebJobs.Extensions.DocumentDB": "1.0.0"
}
}
}
}
local.settings.json
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsDashboard": "",
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"COSMOSDB_CONNECTION_STRING": "AccountEndpoint=https://localhost:8081;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==;"
}
}
I am runnning the function locally using the development storage and Cosmos DB emulator. I tried to translate to F# what it is described here for C#. And it is also pretty much the same as what is mentioned here. But I only get the error Microsoft.Azure.WebJobs.Extensions.DocumentDB: 'Id' is required when binding to a DocumentClient property.
There is a workaround mentioned in this issue on Github. It's fixed in the tooling and will be available with the next release
workaround copied from github
I found the issue and filed https://github.com/Azure/azure-functions-cli/issues/206. The easiest workaround until we have an update:
Go to
C:\Users\{user}\appdata\local\Azure.Functions.Cli\1.0.0.Open
func.exe.configin notepad.Find this:
<dependentAssembly> <assemblyIdentity name="Microsoft.Azure.Documents.Client" publicKeyToken="31bf3856ad364e35" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-1.11.0.0" newVersion="1.11.0.0" /> </dependentAssembly>In both places, replace
1.11.0.0with1.13.0.0so you end up with:<dependentAssembly> <assemblyIdentity name="Microsoft.Azure.Documents.Client" publicKeyToken="31bf3856ad364e35" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-1.13.0.0" newVersion="1.13.0.0" /> </dependentAssembly>Save and retry.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With