Azure Function cosmosDB trigger identity-based connections not working

Cayir Aydar, Aysegul 0 Reputation points
2024-01-24T16:34:29.5933333+00:00

This is 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%",
      "ContainerName": "%contractsContainer%",
      "connection": "ConnectionStrings",
      "createIfNotExists": true
    }
  ]
}

This is local.settings.json:

{
  "IsEncrypted": false,
  "Values": {
    "FUNCTIONS_WORKER_RUNTIME": "python",
    "AzureWebJobsStorage": "",
    "AzureWebJobsSecretStorageType": "files",
    "cosmosDatabase": "",
    "contractsContainer": "",
    "clientId": "",
    "BlobConnStr": "",
    "COSMOSDB_ACCOUNT__accountEndpoint": ""
  },
  "ConnectionStrings": {
    "accountEndpoint": "",
    "credential": "defaultazure"
  }

This is the init.py code snippet:

credential = DefaultAzureCredential()
endpoint = os.environ["COSMOSDB_ACCOUNT__accountEndpoint"]
client = CosmosClient(
    credential=credential,
    url = endpoint
)
database_name = os.environ["cosmosDatabase"]
container_name = os.environ["contractsContainer"]
database = client.get_database_client(database_name)
container = database.get_container_client(container_name)


what is the wrong I am getting this error: In the rest of the code, the file added to blob storage is upserted to cosmosdb. But I am getting an error because my json files are not correct.

System.Private.CoreLib: Exception while executing function: Functions.contracts_blob_trigger. Microsoft.Azure.Cosmos.Client: Response status code does not indicate success: BadRequest (400); Substatus: 0; ActivityId: 71250c6c-6d97-4a1d-b392-87540d6f5fc1; Reason: (Message: {"Errors":["One of the specified inputs is invalid"]}
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,678 questions
Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,639 questions
Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,543 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Pinaki Ghatak 3,265 Reputation points Microsoft Employee
    2024-01-28T18:25:00.1566667+00:00

    Hello @Cayir Aydar, Aysegul The error message you’re seeing, “One of the specified inputs is invalid”, is typically returned when there’s an issue with the inputs provided to the Cosmos DB operation. Here are a few things you could check:

    1. Connection Strings: Ensure that the connection strings for your Azure Blob Storage and Cosmos DB are correctly specified in your local.settings.json file.
    2. Database and Container Names: Verify that the databaseName and containerName values exist in your Azure Cosmos DB account If you’re using automatic value replacement (using %settingName% patterns), make sure that the name of the setting exists in your Azure function app.
    3. Managed Identity: If you’re using Managed Identity, ensure that you have both accountEndpoint and credential specified in your local.settings.json fileThe credential should be set to managedidentity.
    4. Dependencies: The Azure Functions trigger and bindings for Azure Cosmos DB depend on the extension package Microsoft.Azure.WebJobs.Extensions.CosmosDB over the base Azure Functions runtime. Always keep these packages updated, because they include fixes and new features that can help you address any potential issues you might encounter.
    5. Singleton Pattern: If you’re manually creating your own instance of the Azure Cosmos DB SDK client, you should follow the pattern of having only one instance of the client and use a singleton pattern approach This process avoids the potential socket issues in your operations.

    Please review these points and update your configuration accordingly. Let us know if this helps your query


  2. Mike Urnun 9,786 Reputation points Microsoft Employee
    2024-02-14T10:21:26.5733333+00:00

    Hello @Cayir Aydar, Aysegul - We received your feedback that the issue persists despite the suggestions given here on the MS Q&A community. I apologize for getting back to you so late. Based on similar cases that were reported in the past, the “One of the specified inputs is invalid" error is often caused by the input value for the id column not being of a type string. Based on your code, the contract_json_validated() should return the output JSON object in which the id property must be present. Could you verify this part and let me know if that resolves the issue? Please tag me in the comments below and share your findings. I look forward to your reply.

    0 comments No comments