Azure Functions Cosmos DB configuration locally - microsoft-campus-community/workshop-shopping-list-bot GitHub Wiki

Prerequisite: This page assumes that you have a Cosmos DB up and running in Azure. If you do not have one yet, follow the steps to create one first.

This 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

  1. Open the Azure Portal.
  2. Navigate to the resource group you use for this workshop and open the Azure Cosmos DB account in it.
  3. 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.

  1. Open or, if it does not exist, create a file name local.settings.json in the functions 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 the local.settings.json file in Git. Because if you leak your connection string, anyone could manipulate your database, and you will have a data leak 😱.
  2. Paste the following JSON into the local.settings.json file.
{
  "IsEncrypted": false,
  "Values": {
    "FUNCTIONS_WORKER_RUNTIME": "node",
    "SHOPPING_LIST_COSMOSDB": "<YOUR_CONNECTION_STRING_HERE>"
  }
}
  1. Replace <YOUR_CONNECTION_STRING_HERE> with the connection string you copied to the clipboard in the Get the Connection String in Azure paragraph.
⚠️ **GitHub.com Fallback** ⚠️