Azure Functions Configuration in Azure - microsoft-campus-community/workshop-shopping-list-bot GitHub Wiki
the steps to create one first. It also assumes that you have an Azure Function App (page how to create Function App in Azure) running in the cloud.
Prerequisite: This page assumes that you have a Cosmos DB up and running in Azure. If you do not have one yet, followThe Azure Functions use Cosmos DB to persist the items in shopping lists. Now that you have the Azure Functions and a Cosmos DB running in the cloud, it is time to connect both. Otherwise, how is the Azure Function supposed to know where to find the Cosmos DB? Yes, you might have already configured the connection from the Azure Functions to the Cosmos DB locally. However, remember that you never want to check in connection strings to GitHub, so the connection information is lost from your local setup to deployment. It needs to be configured in the cloud again.
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 Function App in Azure
- Open the Azure Portal.
- Navigate to the resource group you use for this workshop and open the resource of type
Function App
in it. - In the navigation on the left side, go to
Configuration
below 'Settings'. - Click '+ New Application setting' under the 'Application settings' section to create a new environment variable available to the Functions running in Azure.
- In the 'Add/Edit application setting' prompt, you will define the environment variable the Azure Functions can use to connect to the Cosmos DB.
- As 'Name' type in
SHOPPING_LIST_COSMOSDB
, which is how the connection string is accessed in the code for the Azure Functions (process.env.SHOPPING_LIST_COSMOSDB
). - For the value, paste the Cosmos DB connection string you retrieved in the Get the Connection String in Azure paragraph.
- Click the 'OK' button to add the application setting.
- As 'Name' type in
- Now that the added application setting shows up in the list, you should not forget to click 'Save'. When prompted that the Function App will restart, click 'continue'. This will make the new application setting available to your Function App.
At this point, your Azure Functions running in the cloud have the environment variable with the Cosmos DB connection string available. The shopping list API is now fully functional.