Using Azure Storage Actions

Azure Storage Actions help us perform large scale actions on blobs across one or more storage accounts from a singular serverless resource. Unlike needing to create an Azure Function, or the manual execution of a Powershell script or a maybe web job, the task is carried out in a way that evolves with the Azure platform and 'should not' require updates to the implementation over time (as seen with Azure Functions and its runtimes becoming out of support as Azure evolves). The most common way to manipulate blobs would have been generally Timer or Blob Storage triggered Functions. This new implementation of Azure Storage Actions offers a new strategy on this.

The Azure Storage Action will have its own resource in a specific region, and therefore your target storage account where your blobs live must be in the same region for this to work properly, there is no support for the Storage Action being able to manipulate data in a storage account in a different region (yes I was confused for a while myself🤔). At the time of writing, Azure Storage Actions are in preview.

Let's set up one here in this blog and target one storage account to test!!

Create Azure Storage Action resource

In the Azure Portal, search for Azure Storage Actions and create the resource in a supported Region (this is preview at the time of writing) for your target resource. Set a Storage task name and click Next:

Create a Storage Account Action resource in a chosen region

Set the Storage Task conditions

Let's take a quick look at the following Storage Task

Set your conditions based on your requirements

This Storage Task will simply take a look at all blobs that meet the conditions of being more than 10MB (the blob Content Length or size is set in bytes) plus containing the .mp4 extension in the name, and then will set the blob tier to 'Cool'. This means those blobs will be moved to slower read access storage in Azure, reducing our general 'at rest' costs for these particular blobs.

Click Next and also skip over Assignments and Tags for now by clicking Next (this will come later), then Review and Create the Storage Action resource:

Review and create the Storage Action resource

Add Storage Task Assignment to a storage account

You now need to add an 'assignment' to the Task you have just made to allow it to run on a specific storage account.

Click on Configure Assignment, then Add Assignment. Set your details as the following for example, noting that the storage accounts that appear here are accounts in the same region as the Storage Action you are creating:

Set filters for the Action to run against. This here assumes we have the blob container called 'media' and that the files will be at this folder level only
💡
If you still happen to see No storage accounts available under your subscription when adding a Storage Task Assignment, you will need to have at least a Storage Blob Contributor RBAC role to do this. Learn about this here . When the storage account is created, the default role assigned role is Storage Blob Data Owner (which is technically more permissions than really required here)

It is important to note that for the above screenshot, it will be cost effective to try and limit what is assessed to a specific blob container prefix. You can add further multiple assignments for different containers perhaps for clearer distinction. If you happened to have millions of blobs or containers, the run would take quite long to scan all files, and you would be charged for all of those read operations!! Scope your containers carefully.

Scrolling further down, add a schedule or set a singular run for the assignment and click Add:

Set a schedule for the assignment and an optional results container to observe what happened when the Action completes
💡
If you need to target other storage accounts in the same region, for the same Storage Task, add new assignments as above and change up the storage account - you will have up to 50 Assignments to add with their own schedules for this Storage Task alone

After the assignment is created and when you are ready, you must Enable it in the Ellipsis menu in the assignment here:

Based on your needs, you will have to Enable the assignment to allow it to run on the schedule it is set on.

Results

After the scheduled time of the Action, refresh the the Assignments blade to see what happened under View Task runs

Storage Action Run Successful!! From the Task runs, you can view the report as a csv if you had optionally set a reporting storage container

This result above indicates that within my 'media' storage container in the storage account, 2 files matched my Conditions that were set earlier, whilst 7 other files were assessed but did not satisfy the Conditions. Once again, remember there will be storage read operation costs associated with this although fairly small (in my case, for my 9 files).

And sure enough, when we observe the 2 updated files, their Access tier has been changed to Cool where they were initially uploaded as Hot:

Modified Access tier on matching blobs

Clean up Resources

As always, remember to clean up any unused resources in Azure!!