Thursday 4 June 2020

Access Azure Storage Blob from Logic App using Blob Connector



Brand New: New Logo for Microsoft Azure

Azure Logic App - Evaluating IF condition with the help of JSON ...


This article briefs about the steps to access the Azure Blob Storage from Logic App using Built-in Connectors - Blob Connector.

Prerequisites:

  1. Logic App with Same/different regions
  2. Azure Storage Blob with  public access set to "Private (no anonymous access)"   . This property can even be modified after the creation of Blob.
   Please refer for more information on Blob : https://docs.microsoft.com/en-us/azure/storage/blobs/

              
                  

Steps :

  1. As a First Step, we will upload some test files into one of the containers for testing purpose of if you have ready that should be fine.
  2. Create a Logic App with recurrence Trigger Or else you can choose Http manual Trigger.
  3. To get content of the blob , first we start with listing the content of the blobs we have with the container.    
  4.        
  5. The output of the List Blobs would have total list of Blobs in an array as shown below:
    "body": {
            "value": [
                {
                    "Id""JTJmdGVzdGNvbnRhaW5lciUyZjFfRnVsbC50eHQ=",
                    "Name""1_Full.txt",
                    "DisplayName""1_Full.txt",
                    "Path""/testcontainer/1_Full.txt",
                    "LastModified""2020-05-29T10:01:57Z",
                    "Size"1464391,
                    "MediaType""text/plain",
                    "IsFolder"false,
                    "ETag""\"0x8D803B752FF5A97\"",
                    "FileLocator""JTJmdGVzdGNvbnRhaW5lciUyZjFfRnVsbC50e",
                    "LastModifiedBy"null
                },
                {
                    "Id""JTJmdGVzdGNvbnRhaW5lciUyZklQX0NhbGMudHh0",
                    "Name""IP_Calc.txt",
                    "DisplayName""IP_Calc.txt",
                    "Path""/testcontainer/IP_Calc.txt",
                    "LastModified""2020-05-29T08:40:55Z",
                    "Size"321,
                    "MediaType""text/plain",
                    "IsFolder"false,
                    "ETag""\"0x8D803AC00D73E9B\"",
                    "FileLocator""JTJmdGVzdGNvbnRhaW5lciUyZklQX0NhbGMudHh0",
                    "LastModifiedBy"null
                }
            ]
        }
  6. Later please choose the action "Create SAS URI by Path" action to generate SAS URI for each blob. We will have to use Path element from previous action result of "List Blobs"
  7. Later the SAS URI for each Blob would be like:
     "body": {
        }

     The SAS URI is fine enough to specify the time span and permissions allowed for access to a storage resource such as a blob or container.
  8. Now the output of the Http action does have the content of the blob as an output.
                        Alright, by above steps we learnt how to get content of all the blobs in the container.
             However, we can even get the blob content dynamically by either passing the container name               and the Filename in Code view.

Note : Azure Blob connector works if both Azure Logic App and Blob in the same or different region provided no Firewall in between.
Logic apps can't directly access storage accounts behind firewalls when they're both in the same region. As a workaround, put your logic apps in a region that differs from your storage account and give access to the
outbound IP addresses for the managed connectors in your region.
 


No comments:

Post a Comment