Implementing Blob Leasing

Start course

Microsoft Azure Storage Accounts are cloud-based data storage repositories for a variety of data types, including blobs, queues, tables, and files. Managing the data in these accounts is often the responsibility of the application developer who uses this data. This course focuses on blob storage and the tools and methods developers can use to manage blobs in Azure Storage Accounts.

The course begins with a brief review of Azure Storage Accounts and then drills down into the details of blobs storage services, highlighting the different kinds of blobs.

The course then focuses on moving blobs between storage containers within a storage account and moving blobs between different storage accounts, using the AZCopy tool, using PowerShell, and programmatically using C#.NET. Next, the course dives into blob properties and metadata and how to set and retrieve this information using the Azure Portal, PowerShell, and programmatically in C#.NET. The course then moves into blob leasing, what it is used for, and how to obtain and manage blob leases using the Azure CLI, the REST API, and C#.NET. The last topic in this course covers data archiving and retention by levering Storage Tiers, the new Lifecycle Management feature in the Azure Portal, and using the immutable storage policies feature.

Learning Objectives

  • Moving items in blob storage between storage containers 
  • Moving items in blob storage between storage accounts
  • Setting and retrieving blob properties and metadata
  • Implementing blob leasing
  • Implementing data archiving and retention

Intended Audience

  • Azure developers who design and build cloud-based applications and services
  • People preparing for Microsoft’s Azure AZ-203 exam


You’ll need to have a basic understanding of Azure, have some experience developing scalable solutions, and be skilled in at least one cloud-supported programming language.


Access to Blob Storage at container or Blob level is controlled by shared access keys and access policies. The files within a container can, and frequently are accessed by multiple users or processes. So there may be times when you need to update a Blob and want to ensure that no other user or process can modify or delete it while you're in the process of updating it. 

Blob Leasing allows you to take ownership of that Blob for a specified period of time, between 15 and 60 seconds, or it could be indefinite. During that time, the Blob can still be read, but it cannot be modified or deleted until the lease expires, or it is released. A Blob can only have one active lease applied to it at a time. Once a lease has expired or been released, another user or process could then acquire a lease on that Blob.

Leases can be acquired and released. They can also be renewed again for the same period of time. Leases may also be broken, which ends the lease but prevents the Blob from being leased again until the first lease has expired. Lastly, a lease can be changed, which simply allows the ID property of the lease to be changed. 

In this demonstration, I'll show you how to acquire and manage Blob leases using the Cloud Shell. From the Azure portal, I've opened up Cloud Shell and selected PowerShell. Now I'll acquire a lease on the wizard.jpg Blob by running the following command. And you'll press enter. PowerShell returns the ID for the lease, and by refreshing my storage account, archived images container, I can see that the wizard Blob has been leased. 

Refreshing the container again, I can see that, now that 30 seconds have expired, that the lease has also expired. I'll renew the lease using the following command. And I'll press enter. 

Now if I refresh my container, I can see that the lease has been renewed. Again, note, that I cannot specify a lease duration. Renewing it, I can only renew it for the same duration as the original lease. 

Now, I'll acquire a lease on the veil jpg Blob, this time setting the lease duration to negative one, making it an infinite lease. And again, PowerShell returns the lease ID. Refreshing my container, I can see that the veil has a lease on it. 

By clicking on it here, I can see that I have the option to break the lease through the Azure portal, however; I'll release the lease again using the Azure command-line interface. And press enter. The command completes, and refreshing the container, I see that the Blob is available for a lease. 

Blob leases can also be managed programmatically using C sharp. The CloudBlockBlob Class has these commonly used methods to manage Blob leases. There are additional methods for managing Blob leases. Consult the Microsoft Azure ADK for .NET at this URL ( 

Blob leases can also be managed using the Azure Storage REST API. Those specifics are beyond the scope of this course, but the details on leveraging this method can be found at this URL (



About the Author

Jeff is a technical trainer and developer residing in Arizona, USA. He has been a Microsoft Certified Trainer for the past 18 years, providing in-house development and training on Microsoft server operating systems, PowerShell, SQL Server and Azure.  When he’s not developing and delivering courses on Azure, he’s photographing galaxies, nebulae and star formations from his computer-automated observatory in Chino Valley, Arizona using a 14” Schmidt Cassegrain telescope.