Azure-Samples / functions-custom-handlers

Sample code for Azure Functions custom handlers
MIT License
91 stars 31 forks source link

Connect to cosmosDB #20

Open captain-yossarian opened 3 years ago

captain-yossarian commented 3 years ago

Hi, it is more question than issue. I know, I can ask it on stackowerflow, but since I'm asking about official way, only you know it.

Is there official way to connect to CosmosDB through RUst custom handler ?

Thanks

fallsimply commented 3 years ago

There is an official way, using input/output bindings. I'd also recommend you install the Azure Functions VSCode Extension (and VSCode if your not already using it)

Samples

listen for updates in the database
cosmosTrigger1/function.json

{
  "bindings": [
    {
      "type": "cosmosDBTrigger",
      "name": "documents",
      "direction": "in",
      "leaseCollectionName": "leases",
      "connectionStringSetting": "AzureWebJobsStorage",
      "databaseName": "database",
      "collectionName": "collections",
      "createLeaseCollectionIfNotExists": "true"
    }
  ]
}

Docs

In the docs, any tab other than C# should have the same function.json as you should use with Rust.

Sidenote: This question could have been asked on StackOverflow as all this info is publicly documented but it takes a good amount of research and a while to understand!

Good luck with your handler and if you need some more help feel free to reply but I can't help with Rust code/syntax

captain-yossarian commented 3 years ago

This question could have been asked on StackOverflow

@fallsimply I have published the question on SO. I'm waiting for your answer ))

judedaryl commented 2 years ago

For anyone who had the same issue. The cosmos db data can be found under Data.”name” ( name is the name you set on the in binding ) in the request body.

I was building my http triggers first and thought the behavior was the same with “enableForwardingHttpRequest” set to true, but this only works for http triggers with every other trigger the function host sends the raw data to a with a post method and route equal to the folder name where the function.json is found.