Adventures with Azure DevOps: Populating Azure Table Storage

Lately, I have been playing around with Azure DevOps, specifically a web application deployment using ARM Templates and Azure PowerShell.

I have a project, and an associated GIT repository, in Azure DevOps where I keep my ARM Templates and PowerShell scripts that I use for the deployment of my web application.

The release pipeline is triggered off of a commit to the master branch.

I have a table in Azure Storage, called lookups.

This is where I store all my lookup data, in this case, a list of all the Sports data available for my web application.

I store the Sports data in my repository in a file called sports.json.

In one of my release tasks, I would like to populate the lookups table with the Sports data.

This can be accomplished through an Azure PowerShell task with the help of the AzureRMStorageTable module.

I am very thankful to Paulo Marques da Costa’s for his article, Working with Azure Tables from PowerShell – AzureRmStorageTable/AzTable PS Module v2.0, this was a huge help in figuring all the nuances of working with Table Storage with Azure PowerShell 2.*.

This feature is only available using Azure PowerShell 2.*, so make sure you set the Task Version to 4.* preview.

Let’s take a look at the PowerShell script.

The script attempts to get the Azure Table Storage table lookups, if it is not found, it then creates thelookups table in Azure Table Storage.

The script takes three parameters:

  • EnvironmentName and EnvironmentShortName are used for naming resources
  • DataPath points to location of the sports.json file

When working locally, I do not pass anything for the DataPath parameter, it will use the root location of the script, while in Azure DevOps, I pass the value of $(System.DefaultWorkingDirectory)/_Teamaloo.Infrastructure/ to the DataPath parameter.

The scripts loads up the sports.json file and starts iterating through each record. It tries to add the record, if that fails, the assumption is the record already exists, and it then updates the record.

One thing I want to call out, in order to get this script to run, I had to add the Install-Module AzureRmStorageTable -Force command at the beginning, using -Force disables any required user interaction.

The AzureRmStorageTable module was not available by default.

I tried using Install-Module AzTable, the updated namespace, but that did not work.

Once I imported this module, everything worked perfectly.

This took me a couple of days to figure out, so hopefully this saves someone else a day or two.

As always, if there is an easier way to do this, please share!

3 Replies to “Adventures with Azure DevOps: Populating Azure Table Storage”

    1. As far as you know is this still currently the best way to insert data into an Azure Storage Table?

  1. Thanks for this post. As far as you know is this still currently the best way to insert data into an Azure Storage Table?

Leave a Reply

Your email address will not be published. Required fields are marked *