1

I want an azure app-function that would be triggered when a new blob is added into the specified container in a storage account and transfer that blob to a specified database and container in Azure CosmosDB. I created an app-function and specified the storage account and container that has to be monitored. In the output binding, I selected Azure CosmosDB as my output binding from portal and specified the details of the CosmosDb account that I had. I tried executing it, but it said

The specified container does not exist

I couldn't understand which container the error was about so I ticked the If true, creates the Azure Cosmos DB database and collection option for the CosmosDB. It didn't make any difference. So I switched to the Advanced Editor to check the function.json, there I found the Output binding type to by "cosmosDB" and a warning green underline under it which stated

Value is not accepted. Valid values: ["documentDB"]

I changed "cosmosDB" to "documentDB" and tried executing it again. This time there was a popup stating

Function (BlobTrigger) Error: The binding type(s) 'documentDB' are not registered. Please ensure the type is correct and the binding extension is installed.
Session Id: 10d62e7e360544009389504620f3506e

Timestamp: 2019-07-24T04:14:08.601Z

I followed https://learn.microsoft.com/en-us/azure/azure-functions/install-update-binding-extensions-manual to add an extension and I added the following extension

Microsoft.Azure.WebJobs.Extensions.DocumentDB Version 1.3.0

After that, I again executed the app-function and it again shows mye the same popup regarding documentDB not registered and if I change back the documentDB to cosmosDb in the advanced editor it again says that the container does not exist. Could someone please pointout where I am going wrong.

Update :

@Jack Jia Yes, I had followed the same procedure you said. In order to re-esure, I retried the process which again gave me the same result. But during this process I realized another issue I had faced. When I was creating the function app, initially it said Deployment failed with

{"code":"DeploymentFailed","message":"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-debug for usage details.","details":[{"code":"Unauthorized","message":"{\r\n \"Code\": \"Unauthorized\",\r\n \"Message\": \"The scale operation is not allowed for this subscription in this region. Try selecting different region or scale option.\",\r\n \"Target\": null,\r\n \"Details\": [\r\n {\r\n \"Message\": \"The scale operation is not allowed for this subscription in this region. Try selecting different region or scale option.\"\r\n },\r\n {\r\n \"Code\": \"Unauthorized\"\r\n },\r\n {\r\n \"ErrorEntity\": {\r\n \"ExtendedCode\": \"52020\",\r\n \"MessageTemplate\": \"The scale operation is not allowed for this subscription in this region. Try selecting different region or scale option.\",\r\n \"Parameters\": [\r\n \"default\"\r\n ],\r\n \"Code\": \"Unauthorized\",\r\n \"Message\": \"The scale operation is not allowed for this subscription in this region. Try selecting different region or scale option.\"\r\n }\r\n }\r\n ],\r\n \"Innererror\": null\r\n}"}]}

But after a while I found the function app I created in my all resources tab and I continued. Maybe thats the reason I am encountering such a issue. But for creating the function app I had refered https://learn.microsoft.com/en-au/learn/modules/chain-azure-functions-data-using-bindings/3-explore-input-and-output-binding-types-portal-lab which clearly states that central india is a valid sandbox location. It would be great if you could guide me here.

  • Why don't you try creating the same functionapp from vscode or vs – HariHaran Jul 24 '19 at 06:48
  • I can try, but what according to you would make a difference. Because I am new to Azure and I feel portal is really comfortable. – Himaja Chandaluri Jul 24 '19 at 07:51
  • 1
    I tested at my side, and got a success. So I think there still might be some mistakes in your settings. Check my answer to see if it helps. – Jack Jia Jul 24 '19 at 08:03
  • Does the blob container exist? The initial error is coming from the storage binding, not Cosmos DB. And you sound like you are using Functions V1, not Functions V2 (that is why `'cosmosDB'` as type didn't work). – Matias Quaranta Jul 24 '19 at 15:01
  • Yes the blob container exists in the same storage account that I used to trigger the function. I am not sure how to change the function app version, but azure claimes that by default any app function created in the azure portal is V2. I will look into. – Himaja Chandaluri Jul 25 '19 at 04:06
  • I checked, I am using Function V2. And now I do not know what happend but the error message has changed to The specified blob does not exist. I have no restriction on the blob name i.e is that path specified is **containername/{name}** – Himaja Chandaluri Jul 25 '19 at 05:34

1 Answers1

0

Just tested (with CosmosDB SQL API), and got a success. Could you please have a further check with the integrate settings?

You can get the database name and collection name from the overview of your CosmosDB:

enter image description here

And set the right values in function app:

enter image description here

The function code:

public static void Run(Stream myBlob, string name, out dynamic outputDocument, ILogger log)
{
    log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
    outputDocument = new { datainfo = name, id = Guid.NewGuid(), contentLength = myBlob.Length };
}

Every time I uploaded a file to the target blob container, a new document would be add to the cosmos DB.

enter image description here

Jack Jia
  • 5,268
  • 1
  • 12
  • 14
  • Please look at the update I made to my question. Thank you. – Himaja Chandaluri Jul 24 '19 at 09:44
  • Hey, I thought it was the deployment failure that caused the issue, so I created a new function app with Central US as the location, but I still get the same error saying the specified container not found. Could you please share your function.json – Himaja Chandaluri Jul 24 '19 at 11:47