Home > Software engineering >  How do I configure my Azure Function's environment so that I can use the CosmosDB client in Pyt
How do I configure my Azure Function's environment so that I can use the CosmosDB client in Pyt

Time:12-16

I am building an Azure Static App with an API written in Python. I'd like to use the Cosmos Client. I'm able to configure my local machine so that local development works:

  • I installed Azure Cosmos into the Python virtual environment: pip install azure-cosmos
  • Inside the Python code, I create and use the client
from azure.cosmos import cosmos_client

cosmos_client.CosmosClient(...)
  • If I launch swa from within the Python virtual environment, things work: (.venv) $ swa start ...
  • I've added the Cosmos Keys to the app's configuration.

But I'm unable to get this code to work in production. I deployed the the code, and the function fails. When I check Application Insights, I see error messages:

Exception while executing function: Functions.my_commands Result: Failure Exception: ModuleNotFoundError: No module named 'azure.cosmos'.

I assume that I must need to run a command or add something to requirements.txt, but I cannot find out what it is.

CodePudding user response:

I assume that I must need to run a command or add something to requirements.txt, but I cannot find out what it is.

To fix this make sure that you have added the below in your requirements.txt file

azure-functions 
azure-cosmos==x.x.x 

For more information please refer this GitHub issue & SO THREAD.

  • Related