Instead of relying on the connection strings for using or testing your application, it is better to use the tokenCredential generated by the instance DefaultAzureCredential. Follow the next steps to achieve the registration of your user on the CosmosDB.
- Get the unique identifier of the role definition in the id property.
az cosmosdb sql role definition list --resource-group "<name-of-existing-resource-group>" --account-name "<name-of-existing-nosql-account>"
- Get the unique identifier for your current account.
az cosmosdb show --resource-group "<name-of-existing-resource-group>" --name "<name-of-existing-nosql-account>" --query "{id:id}"
- Create the role in AZ for
az cosmosdb sql role assignment create -g "<resource_group>" -a "db_account" -d "val_from_step1" --principal-id "your_Entra_id" --scope "val_from_step2"
- Verfiy assignment
az cosmosdb sql role assignment list -g "resource_group" -a "db_account"
Note: for more information visit MS Learn.
This will help you to run an emulator of a blob storage locally in your PC.
-
Download Azurite, or run in your cli:
npm install -g azurite
-
Start azurite
azurite --silent --location azurite --debug azurite/debug.log
- Setup the local environment to work with Azurite by adding the following parameters to the local.settings.json file:
{
"Values": {
"AzureWebJobsSecretStorageType": "Files",
"f6bc32_STORAGE": "UseDevelopmentStorage=true",
"AzureWebJobsStorage": "UseDevelopmentStorage=true"
}
}
NOTE: Look at the file named example.local.settings.json for more details.
Each parameter serves a specific purpose:
AzureWebJobsSecretStorageType
: "Files" tells Azure Functions to store secrets in the local filesystem instead of Azure Key Vaultf6bc32_STORAGE
: This is the connection string used by your contentTrigger function to connect to the blob storage. It's referenced in your code via theConnection
property in the contentTrigger attributeAzureWebJobsStorage
: This is a required setting for Azure Functions runtime. It's used for managing function execution state, storing logs, and coordinating function execution
func start --dotnet-isolated
- Press Ctrl+Shift+P
- Type "Tasks: Run Task"
- Select "func: host start"
- With this tool you will be able to manage the containers used for your local test.
- Create local blob-container. Name it after the string text on the first argument of "contentTrigger", i.e., samples-workitems.
Learn more about blob-storage functions at Microsoft Learn
- Version of Newtonsoft to avoid: versions before 13.0.1