Azure Tips and Tricks Part 136 - Quickly Restore your Local Settings File for Azure Functions

1 minute read

Intro

Most folks aren’t aware of how powerful the Azure platform really is. As I’ve been presenting topics on Azure, I’ve had many people say, “How did you do that?” So I’ll be documenting my tips and tricks for Azure in these posts.

The Complete List of Azure Tips and Tricks

Available Now!

Quickly Restore your Local Settings File for Azure Functions

If you’ve ever worked with Azure Functions then no doubt you’ve seen the local.settings.json file before. This file stores app settings, connection strings, etc. for local development.

It looks like the following to refresh your memory:

{
  "IsEncrypted": true,
  "Values": {
    "FUNCTIONS_EXTENSION_VERSION": "VALUE",
    "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING": "VALUE",
    "WEBSITE_CONTENTSHARE": "VALUE",
    "AzureWebJobsDashboard": "VALUE",
    "AzureWebJobsStorage": "VALUE",
    "ConsumerKey": "VALUE",
    "ConsumerSecret": "VALUE",
    "OAuthTokenSecret": "VALUE",
    "WEBSITE_TIME_ZONE": "VALUE"
  },
  "ConnectionStrings": {}
}

This file is also by default not checked into source control. If you open your .gitignore file you’ll see the following:

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# Azure Functions localsettings file
local.settings.json

With this knowledge, you might have a need one day to restore this file (for example, working with the source code on another machine pulled down from source) and you can easily do so.

Simply install the Azure Functions Core Tools with npm install -g azure-functions-core-tools.

Navigate to the source code where your Azure Function is and run func azure account list. This will ask you to login and you should ensure we are in the proper subscription where your Azure Function exist. You’ll see something like the following:

C:\Users\mbcrump\src\FunctionTest>func azure account list
Subscription                                                                 Current
------------                                                                 -------
Visual Studio Enterprise (xxx)                                               True
Michael's Internal Subscription (xxx)                                        False

If you’re not in the right subscription then type func azure account set <subid> where subid is the correct subscription.

Now run func azure function app fetch-app-settings <functionname> where functionname is your Azure Function and it will restore your local.settings.json file!

That’s it! You now run your app locally again without manually creating this file again.

Want more Azure Tips and Tricks?

If you’d like to learn more Azure Tips and Tricks, then follow me on twitter or stay tuned to this blog! I’d also love to hear your tips and tricks for working in Azure, just leave a comment below.

Leave a Comment