Configuring Azure Storage Emulator to work on different ports

The Azure Functions licensing model operates in a pay-as-you-go model and it consumes a threshold on every execution. Debugging and testing may require a high number of executions, which is not desired when utilising a highly limited free tier. Using Azure Storage Emulator which emulates blob, queue, and table allows avoiding this issue, as well as speeding up the process a little by doing everything locally. However, it may happen that ports used by the emulator are occupied by other software and the default configuration has to be changed or ports have to be freed. In this article, I described both methods and all steps needed to use the custom configuration.

Killing the process

The “Port conflict with existing application” error can be encountered while starting the emulator.

With netstat -p tcp -ano | findstr :<port> commands, one can check what process is blocking the default blob (10000), queue (10001), and table (10002) ports.

PowerShell can be used to kill the application, using the process id – the last value from the previous command output. To stop the task using cmd, the name has to be obtained and passed to the taskkill command.

cmd:
tasklist /fi “pid eq <id>”
taskkill /IM <task_name>

PowerShell:
Stop-Process -ID <id> -Force

Before killing the task, it is a good practice to ensure that it won’t affect the correct operation of an application important to you or your organisation. Access denied can also happen when the process is controlled by your administrator. Either way, the default ports can be changed.

Changing Ports

A configuration file is placed in the Azure Storage Emulator installation folder. If the default installation path was used, it can be found here:
C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe.config
Open the file as an administrator and change all or only the problematic ports.

With the new configuration, the emulator can be turned on. Starting the application reveals if new ports were free. Use AzureStorageEmulator.exe status command to check, if all the services are running correctly.

Configure Azure Storage Explorer

Azure Storage Explorer uses default ports to connect to emulated services. Custom configured local servers can be added by right-clicking on Local & Attached -> Storage Accounts and selecting Connect To Azure Storage

The next step is to select the Local storage emulator and fill in the form with new ports.

Configure Azure Function for local debugging

Debugging attempt can fail with an error similar to the one below:

The listener for function ‘TestFunction’ was unable to start. Azure.Core: Retry failed after 6 tries. Retry settings can be adjusted in ClientOptions.Retry. (No connection could be made because the target machine actively refused it.)

In the local.settings.json file, the storage configuration is provided. Development storage is used for local debugging but "AzureWebJobsStorage": "UseDevelopmentStorage=true" will no longer work. Ports have to be provided explicitly with the connection string. The account used for authentication is saved in the same configuration file as the ports.

The default account data is the same for all installations and the following configuration can be used. 

“AzureWebJobsStorage”: “DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10003/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10004/devstoreaccount1;TableEndpoint=http://127.0.0.1:10005/devstoreaccount1;”

The configuration is completed. I think it is enough to start working with Azure Functions, using the custom configuration of Azure Storage Emulator instead of Azure resources for debugging.