|
| 1 | +--- |
| 2 | +title: "Storage Account" |
| 3 | +description: Get started with Azure Storage Accounts in LocalStack |
| 4 | +template: doc |
| 5 | +--- |
| 6 | + |
| 7 | +import AzureFeatureCoverage from "../../../../components/feature-coverage/AzureFeatureCoverage"; |
| 8 | + |
| 9 | +## Introduction |
| 10 | + |
| 11 | +An Azure storage account serves as a centralized container for all your data objects, including blobs, files, queues, and tables. It provides a unique, globally accessible namespace reachable via HTTP or HTTPS. For more information, see [Overview of storage accounts](https://learn.microsoft.com/en-us/azure/storage/common/storage-account-overview). |
| 12 | + |
| 13 | +LocalStack for Azure provides a local environment for building and testing applications that make use of blobs, queues, and tables. For more information, see: |
| 14 | + |
| 15 | +- [Blob Storage](/azure/services/blob-storage) |
| 16 | +- [Queue Storage](/azure/services/queue-storage) |
| 17 | +- [Table Storage](/azure/services/table-storage) |
| 18 | + |
| 19 | +The supported APIs are available on our [API Coverage section](#api-coverage), which provides information on the extent of Storage Account's integration with LocalStack. |
| 20 | + |
| 21 | +## Getting started |
| 22 | + |
| 23 | +This guide is designed for users new to Azure Storage Accounts and assumes basic knowledge of the Azure CLI and our `azlocal` wrapper script. |
| 24 | + |
| 25 | +Launch LocalStack using your preferred method. For more information, see [Introduction to LocalStack for Azure](/azure/getting-started/). Once the container is running, enable Azure CLI interception by running: |
| 26 | + |
| 27 | +```bash |
| 28 | +azlocal start-interception |
| 29 | +``` |
| 30 | + |
| 31 | +This command points the `az` CLI away from the public Azure management REST API and toward the LocalStack for Azure emulator API. |
| 32 | +To revert this configuration, run: |
| 33 | + |
| 34 | +```bash |
| 35 | +azlocal stop-interception |
| 36 | +``` |
| 37 | + |
| 38 | +This reconfigures the `az` CLI to send commands to the official Azure management REST API. |
| 39 | + |
| 40 | +### Create a resource group |
| 41 | + |
| 42 | +Create a resource group for your storage account resources: |
| 43 | + |
| 44 | +```bash |
| 45 | +az group create \ |
| 46 | + --name rg-storage-demo \ |
| 47 | + --location westeurope |
| 48 | +``` |
| 49 | + |
| 50 | +```bash title="Output" |
| 51 | +{ |
| 52 | + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-storage-demo", |
| 53 | + "location": "westeurope", |
| 54 | + "managedBy": null, |
| 55 | + "name": "rg-storage-demo", |
| 56 | + "properties": { |
| 57 | + "provisioningState": "Succeeded" |
| 58 | + }, |
| 59 | + "tags": null, |
| 60 | + "type": "Microsoft.Resources/resourceGroups" |
| 61 | +} |
| 62 | +``` |
| 63 | + |
| 64 | +### Create a storage account |
| 65 | + |
| 66 | +Create a storage account with the `StorageV2` kind and `Standard_LRS` SKU: |
| 67 | + |
| 68 | +```bash |
| 69 | +az storage account create \ |
| 70 | + --name stordoc86acct \ |
| 71 | + --resource-group rg-storage-demo \ |
| 72 | + --location westeurope \ |
| 73 | + --sku Standard_LRS \ |
| 74 | + --kind StorageV2 |
| 75 | +``` |
| 76 | + |
| 77 | +```bash title="Output" |
| 78 | +{ |
| 79 | + ... |
| 80 | + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-storage-demo/providers/Microsoft.Storage/storageAccounts/stordoc86acct", |
| 81 | + ... |
| 82 | + "kind": "StorageV2", |
| 83 | + "location": "westeurope", |
| 84 | + "name": "stordoc86acct", |
| 85 | + ... |
| 86 | + "primaryEndpoints": { |
| 87 | + "blob": "https://stordoc86acct.blob.core.azure.localhost.localstack.cloud:4566", |
| 88 | + "queue": "https://stordoc86acct.queue.core.azure.localhost.localstack.cloud:4566", |
| 89 | + "table": "https://stordoc86acct.table.core.azure.localhost.localstack.cloud:4566", |
| 90 | + ... |
| 91 | + }, |
| 92 | + "provisioningState": "Succeeded", |
| 93 | + ... |
| 94 | +} |
| 95 | +``` |
| 96 | + |
| 97 | +### Authentication |
| 98 | + |
| 99 | +There are three ways to authenticate storage commands against the emulator: |
| 100 | + |
| 101 | +#### Storage account key |
| 102 | + |
| 103 | +Retrieve the account key and pass it with `--account-name` and `--account-key`: |
| 104 | + |
| 105 | +```bash |
| 106 | +ACCOUNT_KEY=$(az storage account keys list \ |
| 107 | + --account-name stordoc86acct \ |
| 108 | + --resource-group rg-storage-demo \ |
| 109 | + --query "[0].value" \ |
| 110 | + --output tsv) |
| 111 | + |
| 112 | +az storage container list \ |
| 113 | + --account-name stordoc86acct \ |
| 114 | + --account-key "$ACCOUNT_KEY" |
| 115 | +``` |
| 116 | + |
| 117 | +#### Login credentials |
| 118 | + |
| 119 | +Use `--auth-mode login` to authenticate with the current session credentials: |
| 120 | + |
| 121 | +```bash |
| 122 | +az storage container list \ |
| 123 | + --account-name stordoc86acct \ |
| 124 | + --auth-mode login |
| 125 | +``` |
| 126 | + |
| 127 | +#### Connection string |
| 128 | + |
| 129 | +Bundle the account name and key into a single value: |
| 130 | + |
| 131 | +```bash |
| 132 | +CONNECTION_STRING=$(az storage account show-connection-string \ |
| 133 | + --name stordoc86acct \ |
| 134 | + --resource-group rg-storage-demo \ |
| 135 | + --query connectionString -o tsv) |
| 136 | + |
| 137 | +az storage container list \ |
| 138 | + --connection-string "$CONNECTION_STRING" |
| 139 | +``` |
| 140 | + |
| 141 | +The remaining examples in this guide use connection strings for brevity. |
| 142 | + |
| 143 | +### Manage account keys and connection string |
| 144 | + |
| 145 | +List the storage account access keys: |
| 146 | + |
| 147 | +```bash |
| 148 | +az storage account keys list \ |
| 149 | + --account-name stordoc86acct \ |
| 150 | + --resource-group rg-storage-demo |
| 151 | +``` |
| 152 | + |
| 153 | +```bash title="Output" |
| 154 | +[ |
| 155 | + { |
| 156 | + "keyName": "key1", |
| 157 | + "permissions": "FULL", |
| 158 | + "value": "MWFjYTgyZjgtYzU0My00NjE0LThmZDctNzlkODg5ZjU4ZTE5", |
| 159 | + "..." |
| 160 | + }, |
| 161 | + { |
| 162 | + "keyName": "key2", |
| 163 | + "permissions": "FULL", |
| 164 | + "value": "NzliNzVhN2EtYTcwZC00ZTg4LWJkMTQtYjg4MWNlMDJjZDcx", |
| 165 | + "..." |
| 166 | + } |
| 167 | +] |
| 168 | +``` |
| 169 | + |
| 170 | +Regenerate the primary key: |
| 171 | + |
| 172 | +```bash |
| 173 | +az storage account keys renew \ |
| 174 | + --account-name stordoc86acct \ |
| 175 | + --resource-group rg-storage-demo \ |
| 176 | + --key key1 |
| 177 | +``` |
| 178 | + |
| 179 | +Fetch a connection string for data-plane operations: |
| 180 | + |
| 181 | +```bash |
| 182 | +az storage account show-connection-string \ |
| 183 | + --name stordoc86acct \ |
| 184 | + --resource-group rg-storage-demo |
| 185 | +``` |
| 186 | + |
| 187 | +```bash title="Output" |
| 188 | +{ |
| 189 | + "connectionString": "DefaultEndpointsProtocol=https;EndpointSuffix=core.azure.localhost.localstack.cloud:4566;AccountName=stordoc86acct;AccountKey=YWQ5Y2Q2NDYtZTJmOC00ZjU3LWFmOTEtNzk5MjAxNzE1OWQx;BlobEndpoint=https://stordoc86acct.blob.core.azure.localhost.localstack.cloud:4566;FileEndpoint=https://stordoc86acct.file.core.azure.localhost.localstack.cloud:4566;QueueEndpoint=https://stordoc86acct.queue.core.azure.localhost.localstack.cloud:4566;TableEndpoint=https://stordoc86acct.table.core.azure.localhost.localstack.cloud:4566" |
| 190 | +} |
| 191 | +``` |
| 192 | + |
| 193 | +## Features |
| 194 | + |
| 195 | +The Storage Account emulator supports the following features: |
| 196 | + |
| 197 | +- **Control plane REST API**: Storage account CRUD (create, read, update, delete, list), account key management, and name availability checks via Azure Resource Manager. |
| 198 | +- **Multiple authentication modes**: Storage account key, login credentials, and connection strings. |
| 199 | +- **Storage account management**: Create, update, delete, and list storage accounts. Supports `StorageV2`, `BlobStorage`, and `Storage` account kinds with configurable SKU, access tier, and TLS version. |
| 200 | +- **Account key management**: List and regenerate storage account keys (`key1`/`key2`). |
| 201 | +- **Connection string generation**: Retrieve ready-to-use connection strings containing all service endpoints (Blob, Queue, Table, File). |
| 202 | + |
| 203 | +## Limitations |
| 204 | + |
| 205 | +- **Header validation**: Unsupported request headers or parameters are silently accepted instead of being rejected. |
| 206 | +- **API version enforcement**: The emulator does not validate the `x-ms-version` header; all API versions are accepted. |
| 207 | + |
| 208 | +## Samples |
| 209 | + |
| 210 | +The following samples demonstrate how to use Storage Accounts with LocalStack for Azure: |
| 211 | + |
| 212 | +- [Azure Functions Sample with LocalStack for Azure](https://github.com/localstack/localstack-azure-samples/tree/main/samples/function-app-storage-http/dotnet) |
| 213 | +- [Azure Functions App with Managed Identity](https://github.com/localstack/localstack-azure-samples/tree/main/samples/function-app-managed-identity/python) |
| 214 | +- [Azure Web App with Managed Identity](https://github.com/localstack/localstack-azure-samples/tree/main/samples/web-app-managed-identity/python) |
| 215 | + |
| 216 | +## API Coverage |
| 217 | + |
| 218 | +<AzureFeatureCoverage service="Microsoft.Storage" client:load /> |
0 commit comments