Azure Logic Apps — BLOB to CosmosDB

Michal Molka
3 min readMar 1, 2024

Today I walk you through a process of creating a logic app which responsibility is to monitor a BLOB storage container and if any blob is updated or added then a .JSON file is enriched and saved inside a CosmosDB database.

Of course, there are a lot of possibilities for how this task can be solved by a Logic App. This is a simple example, and it is one of many less or more complicated possible solutions.

For a good start. Let’s look at the workflow structure.

A trigger When a blob is added or modified (properties only) (V2) is the first step as a standard. The trigger checks whether a blob is added or modified.

An “/iowa-json-upload” container is monitored and maximum 10 blobs is processed in one run.

The first action Get blob content (V2) gets an uploaded file content. List of Files Path equals an expression triggerBody()?[‘Path’]

This step takes a BLOB content as Base64 format not pure string itself.

So, a Parse JSON step converts a Base64 format into a JSON format. decodeBase64 equals an expression decodeBase64(body(‘Get_blob_content_(V2)’)?[‘$content’])

You need to provide a schema for the final JSON file.

This step Initialize variable initializes a FileName variable and retrieves a file name. replace(…) equals an expression replace(triggerBody()?[‘Name’], ‘.json’, ‘’)

Next two steps Compose set JSON properties.

For a FileName property: setProperty(…) equals setProperty(body(‘Parse_JSON’), ‘FileName’, variables(‘FileName’))

For an Id property: setProperty(…) equals setProperty(outputs(‘Compose_-_set_property_FileName’), ‘id’, guid())

Next two steps Get secret extract a database name and a container name from Key Vault.

The last step Create or update document (V3) inserts or updates the document into a CosmosDB database.

DatabaseID equals body(‘Get_secret_-_database_name’)?[‘value’]

CollectionID equals body(‘Get_secret_-_container_name’)?[‘value’]

Document equals outputs(“Compose_-_set_property_Id”)

This workflow uses a split on approach which creates a separate workflow for every file. So, there is no need to use for each loop if more files are provided. More details are in this post: Azure Logic App — split on and for each

--

--