"тнιѕ вℓσg ¢συℓ∂ ѕανє уσυя мσηєу ιƒ тιмє = мσηєу" - ∂.мαηנαℓу

Monday 8 February 2021

Set up Azure Function with Blob Trigger

If you are not familiar with Azure Blob, please refer this post

https://crmdm.blogspot.com/2021/02/automate-file-copy-to-azure-blob.html

In this post, we will see how to set up an azure function with blob trigger. 

Assumption is that a blob is already set up as explained in the above post. 

So we already have storage account , storage container set up. When a blob is copied into the storage container, azure function gets triggered.

 Let's create an Azure function with Blob trigger from the Visual studio. Here I have used Visual studio 2019. Choose azure function from the templates.

Next step is to name the project.

 

It's time to choose the trigger! Please note the highlighted points. Blob trigger is what we need in this context. Path is the container name. For now, let's put mycontainer and later this can be updated with the value from the Azure. Also connection as MyBlobConnection. This can be mapped to the value from Azure later. So let's click on Create.


Rename function name to the preferred name.

 

 
 Let's define an entry for the connection string. This can be created in local.settings.json as shown. The same values can be configured in the deployed version.


So below are the two items needed from the Azure side.

  • Connection to Azure Blob
  • Container Name  

So let's see how to get these values from Azure. Navigate to the configured Storage Account and choose Access Keys. Click on the Show Keys button. It reveals the Blob connection ( Storage Account ) string. Copy this value.

 


Next bit is the container name

 
Local.settings.json is updated with the connection string from Storage Account.



Azure Function is updated with the container name as well.


We are good to go. Function gets triggered as soon as a blob is added to the storage container.


Inside Azure function you could write additional logic like calling an API, Writing to a SQL Database etc. depending on your requirements.


No comments:

Post a Comment