DEV Community

Shashank Banerjea
Shashank Banerjea

Posted on

Using Azure CLI with local storage emulator

The Beginnings - Unusual Circumstances

While working with a fellow engineer who uses virtualized Linux machine as their primary development environment on Windows 10 PC hosted on Virtual Box, we ran into challenges with accessing the Azure local storage emulator - Azurite, with the Azure Storage Explorer.

The root cause was the corporate proxy settings associated with the laptop that we just could not to resolve.

A mighty unusual start in a way, but that is hand we were dealt.

Finding the path forward

Our project involved developing Azure Functions using Python, which was dependent on use of Azure Storage Queues and access to local development was critical for developer isolation and productivity. But using Storage Explorer became an issue, we were left few options.

First one, drop Linux as our development environment and move to Windows or MacOS, which did not seem to have this issue. Ugly, huh? It also flies right in the face of cross-platform development.

Second one, living the hashtag - #WeAreDevelopers, write some test harness/setup code using the Azure Python SDK and keep it up to date. It was an option, not the most efficient one.

The Middle Ground - Hacked it! or really on shoulder of giants

Azure CLI is a cross platform development for developers and administrators to interact with the Azure Cloud. And until now that is how I had been using Azure CLI, to work with Azure Cloud and not for local development.

So what if, there is a way to use the Azure CLI storage command to work with local storage versus working with Cloud Storage???

IF Only, What IF??

As it turns out, THERE IS. Though not as well documented (as in here in your face... DOCUMENTED), it is possible to stitch the solution using the documentation for Azure Storage Emulator and Configuration for Azure CLI.

The solution

It turns out to be as simple as setting the value a environment variable - AZURE_STORAGE_CONNECTION_STRING, which becomes the default connection string that Azure CLI uses, if a storage account is not specified.

Here is the command to run:


$ AZURE_STORAGE_CONNECTION_STRING="UseDevelopmentStorage=true"
$ export AZURE_STORAGE_CONNECTION_STRING
$ az storage queue create -n myqueue
{
   "created" : true
}

$ az storage queue create -n anotherqueue
{
   "created" : true
}


$ az storage queue create -n newqueue
{
   "created" : true
}


$ az storage queue list --verbose


The Conclusion

Unfortunately, the firewall issues with the corporate laptop still persisted even with this. This approach did not solve the original problem.

But this unusual set of circumstances led me to discover a new way to use Azure CLI. For example - I can use it to test setup scripts, offline for Azure Storage.

So, today as I write this, I am living the motto of my group within Microsoft - "We reserve the right to become smarter".

So my fellow developers - keep hacking and be UNSTOPPABLE!

Top comments (1)

Collapse
 
arphox profile image
Károly Ozsvárt • Edited

In Windows (10), PowerShell, the following command/setting helped me:

$env:AZURE_STORAGE_CONNECTION_STRING = "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;TableEndpoint=http://127.0.0.1:10002/devstoreaccount1;"
Enter fullscreen mode Exit fullscreen mode