Azure Functions Cosmos DB Configuration Locally - microsoft-campus-community/workshop-shopping-list-bot GitHub Wiki
the steps to create one first.
Prerequisite: This page assumes that you have a Cosmos DB up and running in Azure. If you do not have one yet, followThis page explains how to configure your Azure Function project so that it can access the Cosmos DB when you run it locally.
Get the Connection String in Azure
- Open the Azure Portal.
- Navigate to the resource group you use for this workshop and open the
Azure Cosmos DB account
in it. - Open the 'Quick start' page, navigate to the 'Node.js' tab and copy the
PRIMARY CONNECTION STRING
to your clipboard.
Set Connection String in local Azure Function Project.
- Open or, if it does not exist, create a file name
local.settings.json
in thefunctions
folder of your fork of this repository. This file defines the environment variables you want to use in your Azure Function project when running it locally. You never want to share connection strings with others, so do not check thelocal.settings.json
file in Git. Because if you leak your connection string, anyone could manipulate your database, and you will have a data leak 😱. - Paste the following JSON into the
local.settings.json
file.
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "node",
"SHOPPING_LIST_COSMOSDB": "<YOUR_CONNECTION_STRING_HERE>"
}
}
- Replace
<YOUR_CONNECTION_STRING_HERE>
with the connection string you copied to the clipboard in the Get the Connection String in Azure paragraph.