14

How to export and import Azure function's "application settings" ? I have added keys and need to move to new function app. Kindly guide.

user576510
  • 5,777
  • 20
  • 81
  • 144

6 Answers6

40

You have few options here:

Manually

You can do it manually by:

  1. Go to https://resources.azure.com
  2. Search for your app where your app settings are.
  3. go to the "App Settings" view and copy all the JSON there in properties

enter image description here

  1. go to your new app, and navigate to 'App settings' and click edit, and put all that in the properties collection.

Automated:

You can use either the azure-cli, powershell, or azure-functions-core-tools to achieve the same thing.

Powershell:

Using the Azure Powershell modules https://learn.microsoft.com/en-us/powershell/azure/overview?view=azurermps-5.4.0

# get the app settings from app1
$resource = Invoke-AzureRmResourceAction -ResourceGroupName <yourResourceGroupName> -ResourceType Microsoft.Web/sites/config -ResourceName "<yourFunctionAppName>/appsettings" -Action list -ApiVersion 2016-08-01 -Force

# update the other app with $resource.Properties
New-AzureRmResource -PropertyObject $resource.Properties -ResourceGroupName <targetResourceGroupName> -ResourceType Microsoft.Web/sites/config -ResourceName "<targetAppName>/appsettings" -ApiVersion 2016-08-01 -Force

azure-functions-core-tools:

The documentation for that tool is here https://learn.microsoft.com/en-us/azure/azure-functions/functions-run-local

You can do the same by running

az login
func init myFunctionApp
cd myFunctionApp
# this will fetch your settings and put them in local.settings.json
func azure functionapp fetch-app-settings <yourAppName>
func azure functionapp publish <yourTargetApp> --publish-settings-only

the last switch --publish-settings-only is important to not overwrite the files if you only want to publish the settings.

azure-cli:

https://learn.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest

This page should have some documentation about how to retrieve and set app settings using the cli https://learn.microsoft.com/en-us/azure/app-service/scripts/app-service-cli-app-service-storage?toc=%2fcli%2fazure%2ftoc.json

Josh Gallagher
  • 5,211
  • 2
  • 33
  • 60
ahmelsayed
  • 7,125
  • 3
  • 28
  • 40
  • 1
    Thank you sir for saving my time :-) – Kelvin May 10 '18 at 05:27
  • 1
    for the first option let me add this sequence for easy navigation: subscriptions -> *your_subscription* -> resourceGroups -> *your_resourceGroup* -> providers -> Microsoft.Web -> sites -> *your_function* -> config -> appsettings – Giacomo Pirinoli Apr 30 '20 at 09:31
4

You can also get them via the Azure portal:

  1. Select your Functions App in the Azure portal.
  2. Click Download app content in the top bar.
  3. Select Include app settings in the download
  4. Find the file local.settings.json in the download.
Oliver Bock
  • 4,829
  • 5
  • 38
  • 62
2

Currently, it is impossible. You could check this feedback.

One solution, you could clone your web app, see this link. When you clone a app, application settings are also cloned.

Another solution, you could use Power Shell to import application setting and copy the application to a new web app, using following example:

try{
    $acct = Get-AzureRmSubscription
}
catch{
    Login-AzureRmAccount
}

$myResourceGroup = '<your resource group>'
$mySite = '<your web app>'
$myResourceGroup2 = '<another resource group>'
$mySite2 = '<another web app>'

$props = (Invoke-AzureRmResourceAction -ResourceGroupName $myResourceGroup `
        -ResourceType Microsoft.Web/sites/Config -Name $mySite/appsettings `
        -Action list -ApiVersion 2015-08-01 -Force).Properties

$hash = @{}
$props | Get-Member -MemberType NoteProperty | % { $hash[$_.Name] = $props.($_.Name) }

Set-AzureRMWebApp -ResourceGroupName $myResourceGroup2 `
        -Name $mySite2 -AppSettings $hash

More information about this please check this answer

Shui shengbao
  • 18,746
  • 3
  • 27
  • 45
1

Another option is to use Postman.

You can get a JSON with all app settings by making a GET request to the following URL:

https://$AZURE_LOGIN:$AZURE_PASS@$FUNCTION_APPNAME.scm.azurewebsites.net/api/settings

Once the keys are returned you can make a POST request to the new function app's URL and copy that JSON result as the request body with a header Content-Type: application/json.

Username and password can be found from Deployment Credentials in the portal of your Function App.

Aaron Chen
  • 9,835
  • 1
  • 16
  • 28
0

I think Oliver's answer is the easiest one, but just in case, I had the need of retrieving the local.settings.json formatted file from a specific slot (not the root app) that also has keyvault secrets.

So I created this script that gets the configs from an app or a slot app, formats them as a local.settings.json file and if there are keyvaults, it also resolves the values.

I hope it can help somebody, but actually, downloading the app content gives you the file.

0

We can quickly view the json from the "function app → Configuration → Advanced Edit."

enter image description here

Jeevan
  • 518
  • 3
  • 8