Creating a connected architecture with Functions

A connected architecture with Functions refers to creating multiple Functions, whereby the output of one Function triggers another Function and provides data for the next Function to execute its logic. In this section, we will continue with the previous scenario of the Storage account. In this case, the output of the Function being triggered using Azure Storage blob files will write the size of the file to Azure Cosmos DB.

The configuration of Cosmos DB is shown next. By default, there are no collections created in Cosmos DB.

A collection will automatically be created when creating a function that will be triggered when Cosmos DB gets any data.

Create a new database, testdb, within Cosmos DB, and create a new collection named testcollection within it. You need both the database and collection name when configuring Azure Functions. 

It's time to revisit the storagerelatedfunctions function and change its binding to return the size of the data for the uploaded file. This returned value will be written to Cosmos DB. This will require a change to the bindings as well, with an additional one responsible for capturing output values. This binding will eventually write to the Cosmos DB collection. Navigate to the Integrate tab and click on the New Output button below the Outputs label and select Azure Cosmos DB.

Provide the appropriate names for the database and collection (check the checkbox to create the collection if it does not exist), click on the New button to select our newly created Azure Cosmos DB, and leave the parameter name as outputDocument.

Modify the function as shown in the following screenshot:

Now uploading a new file to the orders collection in the Azure Storage account will execute a Function that will write to the Azure Cosmos DB collection. Another Function can be written with the newly created Azure Cosmos DB account as a trigger binding. It will provide the size of files and the Function can act on it. This is shown next: