Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to export and import Azure Function's "application settings"

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

like image 267
user576510 Avatar asked Feb 27 '18 04:02

user576510


3 Answers

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

like image 177
ahmelsayed Avatar answered Oct 19 '22 23:10

ahmelsayed


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.

like image 1
Aaron Chen Avatar answered Oct 19 '22 23:10

Aaron Chen


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

like image 2
Shui shengbao Avatar answered Oct 19 '22 22:10

Shui shengbao