I have a blob trigger function. this code snippet from init.py:
credential = DefaultAzureCredential()
endpoint = os.environ["connect__accountEndpoint"]
client = CosmosClient(
url = endpoint,
credential = credential
)
database_name = os.environ["cosmosDatabase"]
container_name = os.environ["cosmosColl"]
database = client.get_database_client(database_name)
container = database.get_container_client(container_name)
This is my local.settings.json:
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "python",
"AzureWebJobsStorage": "",
"AzureWebJobsSecretStorageType": "files",
"cosmosDatabase": "",
"cosmosColl": "",
"connect__accountEndpoint": "",
"connect__clientId": "",
"BlobConnStr": ""
}
}
This is my function.json :
{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "myblob",
"type": "blobTrigger",
"direction": "in",
"path": "contracts/{name}",
"connection": "BlobConnStr"
},
{
"direction": "out",
"type": "cosmosDB",
"name": "doc",
"databaseName": "%cosmosDatabase%",
"collectionName": "%cosmosColl%",
"connect__accountEndpoint": "connect__accountEndpoint",
"createIfNotExists": true
}
]
}
I am getting this error:
System.Private.CoreLib: Exception while executing function: Functions.contracts_blob_trigger. Microsoft.Azure.WebJobs.Extensions.CosmosDB: Cosmos DB connection configuration 'CosmosDB' does not exist. Make sure that it is a defined App Setting.
I have a problem in Configuration part between json files. How can I handle this error?
First issue is
connect__accountEndpoint. You are using a special notation in Azure Functions that normally means that there is nested JSON:In the
Valuessection. But yourValuessection does not have aconnectionnode with theaccountEndpointandclientIdattributes.But looking at what you are using, you seem to be attempting to use MSI Authentication (accountEndpoint + clientId) which is incompatible with the version of the Extension you seem to be using.
MSI Auth is supported in Extension and Bundles 4.x, for which the names of the attributes and configurations are different (
collectionNameno longer exists, itscontainerName).Please make sure you are using the latest bundle (https://learn.microsoft.com/azure/azure-functions/migrate-cosmos-db-version-3-version-4?tabs=isolated-process&pivots=programming-language-python), and then your
function.jsonwould look like:And your
host.json: