Disable Azure function via AzureCLI does not disable function - azure

I have a function app in Azure that has several functions defined. According to this document, I can use AzureCLI to disable a function in a function app. When I run az functionapp config appsettings set --name $functionAppName --resource-group $resourceGroupName --settings AzureWebJobs.myFunction.Disabled=true it creates the name value pair in application settings as stated in the documentation, but the state of the function does not toggle according to the value I set. Is something else required to toggle the state of the function when I run the AzureCLI commmand?

According to the comments, the problem was solved. OP change the azure function runtime from 1.x to 2.x and then it can be disabled by running this command.
az functionapp config appsettings set --name $functionAppName --resource-group $resourceGroupName --settings AzureWebJobs.myFunction.Disabled=true
Update1:
Update2:
For this problem, I confirmed with azure support team. They provided me with the response below:
They found the feature of az function app config part was released at Sep. 2018, and at that time runtime v1 was already quite out of date. So it is possible that the product team only develops for the runtime v2.
In a word, we can just do this operation on v2 and v3, or use Azure Portal UI.

For the guys who use the runtime 1.x but wanna enable/disable function by Azure CLI. According to the document, it shows:
So the workflow is:
Click APP Service Editor.
Comment out disabled field on function.json.
Run below command again.
az functionapp config appsettings set --name $functionAppName --resource-group $resourceGroupName --settings AzureWebJobs.myFunction.Disabled=true
This function will reference the app setting to determine it status.

Related

Using Az.Websites module to set up user assigned managed identity to pull image from ACR

I am trying to configure my app service to use user assigned managed identity to pull image from ACR. I figured how to do it by using az cli tool.
az resource update --ids /subscriptions/<subscription-id>/resourceGroups/myResourceGroup/providers/Microsoft.Web/sites/<app-name>/config/web --set properties.acrUseManagedIdentityCreds=True
az resource update --ids /subscriptions/<subscription-id>/resourceGroups/myResourceGroup/providers/Microsoft.Web/sites/<app-name>/config/web --set properties.AcrUserManagedIdentityID=$clientId
For certain resons I cannot utilize az cli in my release pipelines. My question is if it would be possible to achieve the same by using Az.Websites, looks like Set-AzWebApp doesn't support this option.
As mentioned in the docs, the current version of the Azure PowerShell cmdlets for Azure App Service do not support user-assigned identities.
You could instead try setting those properties with the Set-AzResource cmdlet.

Azure CLI - Setting Incoming Client Certificates to Allowed for a Web App

I'm trying to use the Azure CLI to update the Incoming Client Certificate option under Web App > Configuration > General Settings > Incoming Client Certificates to use the value Allow.
Currently I can only set the value to true/false which correlates to Require/Ignore.
az webapp update --set clientCertEnabled=true--name MyWebApp --resource-group MyRsGrp
I haven't been able to find anything in the reference documentation.
https://learn.microsoft.com/en-us/cli/azure/webapp?view=azure-cli-latest#az_webapp_update
Does anyone have a nifty way to configure this setting? Thanks!
To set it to Allow, there are two properties need to be set, clientCertEnabled and clientCertMode, clientCertMode is not available in command az webapp update, you need to use az resource update.
Just use the command below, it works for me.
az resource update --name <webapp-name> --resource-group <group-name> --namespace Microsoft.Web --resource-type sites --set properties.clientCertEnabled=true properties.clientCertMode=Optional

Azure- update function code in Function App using CLI

I want to update the code in one of the functions in my Function App using CLI.
I can't find the appropriate command to do so using az functionapp.
What is the best wat yo do this, not using the portal?
If you want to update Function App , you can use the CLI command,
az functionapp update --name MyFunctionApp --resource-group MyResourceGroup
However best practice is to automate by using Azure Devops or GithubActions
You can use the Azure Functions Core Tools:
func azure functionapp publish <FunctionAppName>

Creating Azure function app against existing consumption plan

I have created a function app against a new consumption plan with the following command:
az functionapp create
--resource-group myresourcegroup
--storage-account mystorageaccount
--name myfunctionapp
--runtime node
--consumption-plan-location northeurope
This creates the function app correctly, but the app service plan is called NorthEuropePlan, which does not meet the naming guidelines I am following. I cannot see anything in the docs that will allow me to change this name.
Therefore, I would like to create the app service plan before, as a consumption plan (tier Y1 Dynamic), and then create a function app against this plan.
az resource create
--resource-group myresourcegroup
--name myconsumptionplan
--resource-type Microsoft.web/serverfarms
--is-full-object
--properties "{\"location\":\"northeurope\",\"sku\":{\"name\":\"Y1\",\"tier\":\"Dynamic\"}}"
That command works correctly, and creates me an app service plan. However, when I try to use that plan (substituting --consumption-plan-location northeurope for --plan myconsumptionplan), I get this error:
There was a conflict. AlwaysOn cannot be set for this site as the plan does not allow it.
Do I need to specify some more configuration when I make the app service plan?
When I run az appservice plan show against NorthEuropePlan and myconsumptionplan, the only difference in the object that comes back is the name.
When you are using --plan I believe the run time will think it is an App Service Plan and will configure Always ON which is not allowed in consumption plan so I guess you cannot do it like the way you are doing.
You can achieve it with ARM template though. Below is the example command:
az group create
--name ExampleGroup
--location "North Europe"
az group deployment create
--name ExampleDeployment
--resource-group ExampleGroup
--template-uri "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-function-app-create-dynamic/azuredeploy.json"
The URL mentioned in the template-uri is sample template which will create consumption-pan, storage and functionapp.
Deployment will ask the name of parameters (appName) at runtime.

Azure CLI. Is it possible to update/set default documents for web app?

I have a web app on azure and i want to add a value app_offline.htm in Default Documents through azure cli 2.0:
I looked at az webapp config appsettings set, but this sets the config and not the default document.
Did someone encounter this?
Is there a solution to doing this through CLI and not manually through Azure UI?
Of course you can.
You could try the command below, replace the <yourresourcegroup> and <yourwebappname>, it works fine on my side.
az resource update --resource-group <yourresourcegroup> --resource-type "Microsoft.Web/sites/config" --name <yourwebappname>/config/web --add properties.defaultDocuments app_offline.htm
Changing that setting is not currently possible in Azure CLI 2.0, but it would be great if you could file an issue here (better when it comes from customers).
However, you can use Azure PowerShell to achieve this today.
$webapp = Get-AzureRmWebApp -ResourceGroupName rg -Name name
$webapp.SiteConfig.DefaultDocuments.Add("new.html")
Set-AzureRmWebApp $webapp

Resources