Sign in during Public Preview to get the Team plan free, plus an early-adopter discount when we launch. Sign in
This guide shows you how to provision a Storage Account against Locally, and then write and read a blob in it. As with the other guides we're going to use the Azure CLI, but the same resource can be provisioned with HashiCorp Terraform, Pulumi or Bicep too.
az) installed.Firstly, we need to launch Locally which we can do from a terminal by running:
$
locally build
Once Locally has started, the Locally Dashboard will open automatically:
Next we can create the Resource Group to hold the Storage Account:
$
locally run az group create -n sample-resources -l berlin
There's two things to note here:
locally run.locally run when you do.With the Resource Group in place, we can create the Storage Account:
$
locally run az storage account create --name samplestorage1 --resource-group sample-resources --location berlin --sku Standard_LRS
Note
The response includes the endpoints for each of the storage services:
{
"note": "some fields skipped for brevity",
"name": "samplestorage1",
"primaryEndpoints": {
"blob": "https://samplestorage1.blob.core.storage.locally:5660/",
"dfs": "https://samplestorage1.dfs.core.storage.locally:5660/",
"file": "https://samplestorage1.file.core.storage.locally:5660/",
"queue": "https://samplestorage1.queue.core.storage.locally:5660/",
"table": "https://samplestorage1.table.core.storage.locally:5660/",
"web": "https://samplestorage1.web.core.storage.locally:5660/"
},
"provisioningState": "Succeeded",
"type": "Microsoft.Storage/storageAccounts"
}
Those storage.locally hostnames are served by Locally's own DNS server and point at the Storage Emulator running on your machine.
Blobs live in a container, and Locally has a built-in command for creating one:
$
locally storage container create --account samplestorage1 --name files
Container "files" created in account "samplestorage1".
Note
locally storage is part of Locally itself, so it doesn't take the locally run prefix. Every az command does.If you'd rather use the Azure CLI, az storage container create works too, once it has the account's connection string from the next step.
The locally storage commands manage containers, queues, shares and tables, but not the blobs inside them, so for those we'll use the Azure CLI. Like the Azure SDKs, it needs the account's connection string. locally storage connection-string prints it, and putting it in AZURE_STORAGE_CONNECTION_STRING means the az storage commands below pick it up automatically:
$
export AZURE_STORAGE_CONNECTION_STRING=$(locally storage connection-string --account samplestorage1)
The connection string looks like the Azure one, pointed at your machine:
DefaultEndpointsProtocol=https;AccountName=samplestorage1;AccountKey=...;BlobEndpoint=https://samplestorage1.blob.core.storage.locally:5660/;FileEndpoint=https://samplestorage1.file.core.storage.locally:5660/;QueueEndpoint=https://samplestorage1.queue.core.storage.locally:5660/;TableEndpoint=https://samplestorage1.table.core.storage.locally:5660/
Now create a small file and upload it to the container:
$
echo 'hello from Locally' > hello.txt
$
locally run az storage blob upload --container-name files --name hello.txt --file hello.txt
We can confirm it's there:
$
locally run az storage blob list --container-name files --query "[].{Name:name, Size:properties.contentLength}" -o table
Name Size
--------- ------
hello.txt 19
And read it back out again:
$
locally run az storage blob download --container-name files --name hello.txt --file downloaded.txt
$
cat downloaded.txt
hello from Locally
Note
We can see the Storage Account in the Locally Dashboard too:
Finally, we can tidy up. To remove the Resource Group and everything within it:
$
locally run az group delete -n sample-resources --yes
There's nothing billable to clean up, since everything ran on your machine, but it's still worth checking your teardown scripts work here before you run them against Azure.
Whilst this guide used the Azure CLI, Storage Accounts work the same way through any of the tooling that Locally supports - a Microsoft.Storage/storageAccounts resource in HashiCorp Terraform or OpenTofu, Pulumi, Bicep or an ARM Template all provision against Locally in the same way, with only the location changed.
The same is true of the data plane: hand the connection string above to the Azure SDK for .NET, Go or Python and your application reads and writes blobs against Locally.
To use queues in a Storage Account, see Storage Queues. Every Function App keeps its state in a Storage Account too.
Should you encounter any issues, please take a look at the troubleshooting section.
Sign in during Public Preview to get the Team plan free, plus an early-adopter discount when we launch. Sign in
Your Azure infrastructure, running on your machine. Deploy in seconds, break things freely, and ship to Azure when you're ready.