简体   繁体   中英

Problem with the binding type of azure app-function when sending data from blob storage to cosmosDB whenever a blob is added into a container

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://docs.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://docs.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.

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:

在此处输入图片说明

And set the right values in function app:

在此处输入图片说明

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.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM