The following project contains a sample on maintaining and reusing a Azure Cosmos DB V3 client. The concept is valid for any HTTP-based client library/SDK.
It contains a single sample:
- Startup: Create and maintain a custom
CosmosClient
instance to be reused in all the Function's executions through ASP.NET Core Dependency Injection. - HttpTriggerToStaticClient: Pulls in the singleton
CosmosClient
and when the Function receives a POST with a particular payload, it uses it to store it as a new document.
You can use Visual Studio Code, Visual Studio or even the Azure Functions' CLI. You only need to customize the local.settings.json file to match the Cosmos DB Connection String, Preferred Region, Database name, and Container name on which you want the client to be created and documents to be saved.