(9) Create an API resource
{{% alert title="INFO" color="info" %}} You shouldn't communicate with the CosmosDB directly from the website user counter as this would expose security vulnerabilities. Instead, create the code that performs the read/update action in the CosmosDB as an API. You call this API from the user counter and the API then connects with the CosmosDB and returns the data. {{% /alert %}}
Goal 1: Get Azure function talking to the database¶
- Create an Azure Function using Python
- Setup Bindings between the function and the database
- https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-cosmosdb-v2?tabs=in-process%2Cfunctionsv2&pivots=programming-language-csharp#add-to-your-functions-app
- Create python code that saves a value to the database
- Setup output bindings so the updated value is returned from the function
- https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-http-webhook-output?tabs=in-process&pivots=programming-language-python