Back

Azure Blob Storage API Essential Guide

Aug 7, 20246 minute read

What type of API does Azure Blob Storage provide?

Azure Blob Storage primarily uses a REST API. Here are the key points about Azure Blob Storage's API:

REST API

  1. Azure Blob Storage offers a comprehensive REST API for programmatic access to blob data.

  2. The REST API supports operations on storage accounts, containers, and blobs.

  3. It allows for creating, reading, updating, and deleting blobs, as well as managing containers and storage account properties.

Key Features of the REST API

  1. The API supports different types of blobs: block blobs, append blobs, and page blobs.

  2. It provides operations for listing containers and blobs, setting and retrieving metadata, and managing access control.

  3. The API includes support for leasing blobs and containers, creating snapshots, and copying blobs.

  4. It offers operations for querying blob contents and setting blob tiers.

API Structure

  1. The API is structured around resources: storage accounts, containers, and blobs.

  2. Each resource type has its own set of operations, such as Create Container, Get Blob Properties, or Put Block.

  3. The API uses standard HTTP methods (GET, PUT, POST, DELETE) for different operations.

Best Practices

  1. HTTPS is highly recommended over HTTP for security reasons.

  2. The API supports conditional update operations, which can be useful for concurrency control.

  3. For large blobs, consider using operations like Put Block and Put Block List instead of a single Put Blob operation.

Does the Azure Blob Storage API have webhooks?

Yes, Azure Blob Storage supports webhooks through Azure Event Grid.

Azure Blob Storage supports the following event types that you can subscribe to:

  • Microsoft.Storage.BlobCreated
  • Microsoft.Storage.BlobDeleted
  • Microsoft.Storage.BlobRenamed
  • Microsoft.Storage.DirectoryCreated
  • Microsoft.Storage.DirectoryDeleted
  • Microsoft.Storage.DirectoryRenamed

Events are pushed using Azure Event Grid to subscribers such as Azure Functions, Azure Logic Apps, or custom HTTP listeners. Event Grid provides reliable event delivery with retry policies and dead-lettering.

Common scenarios for using Azure Blob Storage events include image/video processing, search indexing, and file-oriented workflows. Events are available for general-purpose v2 storage accounts and Blob storage accounts.

Best practices for consuming events include:

  • Checking the topic of the message to ensure it's from the expected storage account.
  • Verifying the eventType is one you're prepared to process.
  • Using etag fields to check if object information is up-to-date.
  • Using sequencer fields to understand the order of events on a particular object.
  • Being aware that duplicate messages may occur due to at-least-once delivery guarantee.
  • Using the blobType field to understand allowed operations and appropriate client library types.

To set up event subscriptions, you need to:

  1. Create a storage account (if not already done).
  2. Subscribe to the storage account events using Azure CLI, PowerShell, or Azure Portal.
  3. Provide an endpoint (e.g., web app, Azure Function) to receive the events.
  4. Implement proper handling of the events in your code.

Remember to use HTTPS for webhook endpoints and consider using Azure Functions or Logic Apps for easier integration with Azure services.

Rate Limits and other limitations

Here are the key points about API rate limits for Azure Blob Storage:

General Limits

  • For a standard storage account, you can make up to 20,000 requests per second against the storage account.

  • There is no explicit rate limit exposed by the Azure Storage REST API. However, if you exceed the throughput quota (e.g. more than 20,000 requests/second), Azure Storage will start throttling your requests.

Management Operation Limits

For management operations using Azure Resource Manager with Azure Storage, the following limits apply per region:

  • Storage account management operations (read): 800 per 5 minutes
  • Storage account management operations (write): 10 per second / 1200 per hour
  • Storage account management operations (list): 100 per 5 minutes

Blob-Specific Limits

  • Target request rate for a single blob: Up to 500 requests per second
  • Target throughput for a single page blob: Up to 60 MiB per second
  • Target throughput for a single block blob: Up to storage account ingress/egress limits

Key Points to Consider

  • The actual request rate and bandwidth achieved depends on factors like object size, access patterns, and workload type.

  • If you hit rate limits, Azure Storage may return 503 (Server Busy) or 500 (Operation Timeout) errors.

  • It's recommended to use exponential backoff for retries if hitting 503 errors to ease load on the partition.

  • There are also limits on things like blob sizes, number of blocks, etc. that are not strictly rate limits but may impact overall performance.

Best Practices

  • Test your application to determine if it meets your performance requirements.

  • Avoid sudden traffic spikes and try to distribute traffic across partitions.

  • Use exponential backoff retry policies when hitting throttling errors.

  • Monitor your usage and request patterns to stay within the limits.

  • Consider using the Azure Storage resource provider limits as guidance for management operations.

In summary, while there are some specific limits for management operations, the main throttling for data operations is based on overall account throughput rather than a fixed API request limit. Proper testing and monitoring is key to optimizing performance within these constraints.

Latest API Version

The most recent version of the Azure Blob Storage API is 2024-11-04.

Key points to consider:

  1. This is the current version as of August 8, 2024 (the date provided in the context) [1].

  2. Microsoft recommends using the latest version (2024-11-04) where possible [1].

  3. The 2024-11-04 service version includes the following new features [2]:

    • Support for token-based authentication for all data plane APIs in the files service
    • Support for paid bursting on premium file share accounts
    • Support for the binary format when getting and setting file permissions in the files service
  4. Azure Storage supports multiple versions, and you must specify the version you want to use for each operation, unless the request is anonymous [2].

  5. For requests using Shared Key or Shared Key Lite authentication, you can pass the x-ms-version header on the request to specify the version [2].

  6. For requests using a shared access signature (SAS), you can specify two versioning options:

    • The optional api-version header indicates which service version to use for the API operation
    • The required SignedVersion (sv) parameter specifies the service version to use for authorization [2]
  7. For anonymous requests to Blob Storage accounts, if no version is specified and no default version is set, the service uses the earliest possible version (2014-02-14 for Blob Storage accounts) [2].

Best practices:

  1. Always use the latest version of the API when possible to take advantage of new features and improvements.

  2. Be aware of version compatibility when working with different clients or services that may use older versions of the API.

  3. When using shared access signatures, make sure to specify both the api-version and SignedVersion (sv) parameters to ensure consistent behavior.

  4. Keep your client libraries up to date to support the latest API versions. For example, the Azure Storage Blobs client library for .NET is currently at version 12.21.1 [5].

  5. When developing applications, consider using the Azure SDK libraries, which abstract away many of the version-specific details and provide a more consistent experience across different Azure services.

How to get a Azure Blob Storage developer account and API Keys?

To get a developer account for Azure Blob Storage and create an API integration, you'll need to follow these steps:

1. Create an Azure Account

First, you need to create an Azure account if you don't already have one. You can sign up for a free account at https://azure.microsoft.com.

2. Create a Storage Account

Once you have an Azure account:

  1. Log in to the Azure portal (https://portal.azure.com)
  2. Create a new storage account
  3. Choose the appropriate subscription, resource group, and region
  4. Select the account type (usually "StorageV2 (general purpose v2)")
  5. Choose the replication and performance options that suit your needs

3. Obtain Access Credentials

After creating the storage account:

  1. Go to your storage account in the Azure portal
  2. Under "Settings", click on "Access keys"
  3. Here you'll find your storage account name and access keys

4. Set Up API Integration

To integrate Azure Blob Storage with your application:

  1. Install the Azure Storage SDK for your programming language
  2. Use the storage account name and access key to authenticate your requests
  3. Alternatively, you can use Azure Active Directory (Azure AD) for authentication

What can you do with the Azure Blob Storage API?

Here's the markdown text with the trailing list of URLs and citation references removed, and any URLs inside the content formatted correctly for the markdown file format:

Here's a breakdown of the data models you can interact with using the Azure Blob Storage API and what is possible for each:

Storage Account

  • List all containers in the storage account
  • Set and get Blob Storage properties, including logging and metrics settings
  • Retrieve statistics related to replication (only available on secondary location endpoints)
  • Get account information (SKU name and account kind)
  • Get a user delegation key for signing user delegation shared access signatures

Containers

  • Create new containers
  • Get and set container properties and metadata
  • Get and set container access control lists (ACLs)
  • Lease containers (establish and manage locks for delete operations)
  • Delete containers and their contents
  • List blobs within a container

Blobs (Block, Append, and Page)

  • Put (create or replace) blobs
  • Get (read or download) blobs, including metadata and properties
  • Set blob properties and metadata
  • Delete blobs
  • Lease blobs (establish and manage locks for write and delete operations)
  • Create snapshots of blobs
  • Copy blobs between storage accounts
  • Undelete soft-deleted blobs
  • Set blob tiers (for block and page blobs)
  • Get and set blob tags

Block Blobs (specific operations)

  • Put individual blocks
  • Put blocks from URLs
  • Put block lists (commit blocks to a blob)
  • Get block lists
  • Query blob contents using SQL-like statements
  • Set blob expiry

Append Blobs (specific operations)

  • Append blocks to the end of the blob

Page Blobs (specific operations)

  • Put pages (write ranges of pages)
  • Get page ranges
  • Perform incremental copy operations

Additional Features

  • Find blobs by tags across containers
  • Use SFTP for secure connections
  • Mount Blob Storage containers using NFS 3.0 protocol
  • Utilize hierarchical namespace for Data Lake Storage Gen2 capabilities

This list covers the main operations and data models you can interact with using the Azure Blob Storage API. Each model (Storage Account, Containers, and different types of Blobs) offers specific operations tailored to its purpose and characteristics.