This article is contributed. See the original author and article here.

Scenario:


With RA-GRS redundancy, you can read the data using secondary endpoint. The document points at connecting to Blob Storage using secondary endpoint and read data ahead.


 


Actions:


We will be making use of connection string to connect to the secondary endpoint and follow the below steps:


 


Step 1: Obtain the connection string.


We can obtain this from Azure Portal, from Access Keys section under Security & Networking Pane of Storage Account Blade.


Amrinder_Singh_0-1622550002176.png


 


Step 2: Editing connection string to use Secondary Endpoint.


Append the BlobEndpoint section pointing to secondary endpoint at the end of the connection string like the one given below:


 


DefaultEndpointsProtocol=https;AccountName=<StorageAccountName>;AccountKey=35tCZY3DXXXXXXXXXXXXXXXXXXXXXXXXXX==;EndpointSuffix=core.windows.net;BlobEndpoint=https://<StorageAccountName>secondary.blob.core.windows.net


 


In case you want to leverage SAS, then you can edit the SAS URL to add secondary keyword after the account name and blob as endpoint. Below is one of the sample SAS URL:


https://<StorageAccountName>secondary.blob.core.windows.net/?sv=2020-02-10&ss=bfqt&srt=sco&sp=rwdlacuptfx&se=2021-05-29T11:38:06Z&st=2021-05-29T03:38:06Z&spr=https&sig=XXXXXXXXXXXXXXXXXXXXXX


 


Step 3: Connecting to Storage Account using the connection string.                                 


We will try connecting and accessing blobs using Azure Storage Explorer and via a powershell script. Let’s check for the process with first option.


 


When accessing via Azure Storage Explorer, you can follow the below steps of first selecting the resource type as Storage account.


Amrinder_Singh_1-1622550106941.png


 


Select the connection method as connection string and then provide the connection string created at step 2 along with the display name using which you want the connection to be displayed. Once done, click on the connect button.


Amrinder_Singh_6-1622550296283.png


 


Amrinder_Singh_4-1622550157468.png


At this point, the connection will get added under the Storage Accounts section of Local & Attached.


 


Step 4: Validations


To validate you are hitting the secondary endpoint only, you can configure fiddler as a proxy in the storage explorer and then try performing the operation of listing and reading (Get operation) while running the fiddler in the backend.


Amrinder_Singh_8-1622551523309.png


 


At the backend, you will see that you are hitting the secondary endpoint while trying to access the blobs.


Amrinder_Singh_7-1622550737487.png


 


In order to connect using Powershell, you can leverage below script to listing of the blobs inside a container.


 


$bMaxReturn = 100  


 


$storageContext = New-AzStorageContext -ConnectionString “<String Generated at Step 2>”


 


do   


{   


    # get a list of all of the blobs in the container    


    $listOfBlobs = Get-AzStorageBlob -Container “<Container Name>” -Context $storageContext -MaxCount $bMaxReturn -ContinuationToken $bToken    


                 if($listOfBlobs.Length -le 0) { Break;}   


          foreach($blob in $listOfBlobs) {   


               write-host “Blob name:” 


               write-host $blob.Name 


               } 


                    $bToken = $blob[$blob.Count -1].ContinuationToken; 


}while ($bToken -ne $Null)     


 


Disclaimer


By using the following materials or sample code you agree to be bound by the license terms below and the Microsoft Partner Program Agreement the terms of which are incorporated herein by this reference. These license terms are an agreement between Microsoft Corporation (or, if applicable based on where you are located, one of its affiliates) and you. Any materials (other than sample code) we provide to you are for your internal use only. Any sample code is provided for the purpose of illustration only and is not intended to be used in a production environment. We grant you a nonexclusive, royalty-free right to use and modify the sample code and to reproduce and distribute the object code form of the sample code, if you agree:



  • to not use Microsoft’s name, logo, or trademarks to market your software product in which the sample code is embedded.

  • (ii) to include a valid copyright notice on your software product in which the sample code is embedded.

  • (iii) to provide on behalf of and for the benefit of your subcontractors a disclaimer of warranties, exclusion of liability for indirect and consequential damages and a reasonable limitation of liability; and

  • (iv) to indemnify, hold harmless, and defend Microsoft, its affiliates and suppliers from and against any third-party claims or lawsuits, including attorney’s fees, that arise or result from the use or distribution of the sample code.”


For any information regarding data redundancy, you can check this link.


 


Hope this helps!

Brought to you by Dr. Ware, Microsoft Office 365 Silver Partner, Charleston SC.