CloudForDummies
Published in

CloudForDummies

Local Azure Storage Emulation with Azurite and Azure Functions — A Dummies Guide

Azure

If you work with Azure Storage events, you are in the right place. This article is not about the different classes of storage , but how to emulate them locally with Azurite. We will be emulating Azure storage locally to test events (functions ) triggered by Azure storage types .

Azurite currently supports Blob , Queue and Table storage emulation . If you are new to Azure Storage , it will be helpful to give a read to the article below.

If you are new to Azure Functions , you may consider reading my other articles on Azure Functions.

Alternatively, you can also check out my medium publication for more articles on Azure Functions.

First things first

Before proceeding further we need some tools ready in your laptop. I run Linux and even for Windows mostly the steps are the same except for Docker installation sometimes ( in older Windows 10 versions Docker support is not too great ) .

  1. Docker (Docker Installation for Windows , Docker Installation for Linux )

2. Azure Storage Explorer

3. Azure Functions Core Tools

4. Python ( as I prefer Python ) .

Note :

  1. If you are comfortable with another language you may have to go your way after step 4. Only steps 1 to 3 are critical in setting up the local storage emulation infrastructure. The remaining are standard Azure Function setup and development related.
  2. Using VS Code makes a life a lot easier dealing with Azure Resources. However , its totally a personal opinion. You can replicate these steps with any of your favorite Code Editor.

In fact in this article , I’m not going to use VS code to run the functions and stick to command line .

Assuming you have setup your environment lets get cracking.

Steps

  1. Download the Azurite Docker image
docker pull mcr.microsoft.com/azure-storage/azurite

After this when you run the following command you should be able to see the docker image.

sudo docker image ls

2. Run the Docker image

docker run -p 10000:10000 -p 10001:10001 -p 10002:10002 \
mcr.microsoft.com/azure-storage/azurite

Now observe the output carefully . You will see that each service Blob , Queue , Table is associated with a dedicated port.

If you are looking to run a specific type of storage you can try this command

docker run -p 10000:10000 mcr.microsoft.com/azure-storage/azurite \
azurite-blob --blobHost 0.0.0.0 --blobPort 10000

Just the change the highlighted parts to the relevant storage type such as queue or table and proceed.

3. Configure the Storage Emulator

Your Azure Storage Emulator application has a startup page like this. Click on the “plug” icon to get the connect manager

Click on Local Storage Emulator

Just the name the connection as “Azurite” and leave everything default ( unless you made a change when you started the docker container ) and hit next .

Now you should your Azurite Storage Emulator visible

Now you have successfully configured your local storage emulator. Let’s test this quickly.

To test this I’m going to create a simple Queue trigger with Azure Functions.

Before doing that, I’m going to create a queue called “test-local-queue” in my storage emulator window.

Simply , right click the Queues and “Create a queue”. Remember to use the same name or at the least any name without underscores. Azure Storage naming conventions are to blame.

Before proceeding further, you might see some interesting logs getting generated by the docker image that we started. They are simply logs for actions that we did in the storage emulator.

4. Create a Queue trigger function

I have covered Queue trigger functions in detail in the article below which deals with Cloud storage.

But for the benefit of this tutorial , let’s create one quickly “locally”. I’m going to use command-line with Azure Functions Core tools .

Let’s start

func init

And select the option 4 ( as I’m using Python ) . If you are comfortable with another language you may want to choose the relevant option.

Now we have the function boilerplate code created .

Let’s create a queue trigger function now with the following code and select option 12 for queue trigger

func new

I named the function as test-local-queue-trigger as a reminder to the queue that I created in Step 3

Let’s make some changes to the queue function and test the trigger.

Before we proceed further , I’d like to show the folder structure created as part of the steps above.

5. Edit the localsettings.json in the functions app

The default boiler plate code looks like this. We are going to add a couple of items here

Use the following . But before that let’s observe that we have used the values “UseDevelopmentStorage=true” . This let’s the function run-time where to look for events.

Also, look at the QueueConnectionString that I have created. I’m going to use it in a short while.

First let’s understand how to obtain the Connectionstring. It’s simple . It’s available in the Storage Emulator.

Look at the Primary Connection string.

Let’s observe the connection string a bit and the highlighted ones

AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;DefaultEndpointsProtocol=http;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;TableEndpoint=http://127.0.0.1:10002/devstoreaccount1;

6. Edit the function.json in the function to tell the function which queue it should look for

Default Settings look something like this

Change the queueName to “test-local-queue” and save the file.

7. Let’s test the Queue trigger by running the function in command line

func start

You’ll also see a lot of action happening in the docker image .

Don’t worry about the warning message on “connection” property . We have already set it up in the localsettings.json .

Let’s put a message in the queue

As soon as you insert the message , you can see the message getting processed in the command line with as the function has triggered.

And that’s how you emulate a Queue Storage with Azurite locally.

As with Blob storage and Table storage , the process is really simple and identical to that of a queue storage.

Steps you need to remember to replicate is to pick the right type of function trigger and link the function trigger to the blob / table created in the local storage.

I hope you liked it and found all the minor details you need to test Azure Storage emulation with Azure Functions .

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store