Question

Difficulty: MediumPerform Blob and Container Operations using Azure Storage SDKs

You are developing a C# background service that must safely update the content of an existing blob named config.json in Azure Blob Storage. To prevent concurrency conflicts, your service must lock the blob using a lease before performing the upload and release the lease immediately afterward. You are using the Azure.Storage.Blobs (v12) SDK.

Order the steps required to implement this lease-based upload workflow.

  1. 1Create a BlobClient instance for the config.json blob.
  2. 2Instantiate a BlobLeaseClient by calling GetBlobLeaseClient() on the BlobClient.
  3. 3Call AcquireAsync() on the BlobLeaseClient to lock the blob and receive a lease ID.
  4. 4Call UploadAsync() on the BlobClient, passing the lease ID inside a BlobUploadOptions object's Conditions property.
  5. 5Call ReleaseAsync() on the BlobLeaseClient to unlock the blob.

Answer

The correct order of operations is to first create the BlobClient, then instantiate the BlobLeaseClient, acquire the lease, upload the blob content with the lease ID included in the request conditions, and finally release the lease.
To safely modify a leased blob, you must establish client references, acquire the lock to obtain a lease ID, supply that lease ID with the upload request, and release the lock when the operation is complete.

Step-by-Step Solution

1
Instantiate the BlobClient client.
A BlobClient object representing config.json is created.
This object is the starting point for interacting with the blob.
2
Instantiate the BlobLeaseClient client.
A BlobLeaseClient object linked to the BlobClient is created.
The lease client manages all lock-related actions on that blob.
3
Acquire the lease.
A Lease object is returned containing the unique LeaseId.
This locks the blob against unauthorized updates.
4
Upload content with the lease ID.
The blob is updated with the new content.
Passing the lease ID in the request conditions authorizes the update.
5
Release the lease.
The lease is removed from the blob.
Releasing the lease unlocks the blob for subsequent operations.

Key Concept

Lease management workflow in Azure Storage Blobs C# SDK
Estimated Time:1m 30s
Rate this question