I have a PowerShell script which creates an azure function app on a consumption plan and its associated storage account within a resource group using the azure cli following the example In the Microsoft Docs
However to enable application insights I have to go to the azure portal, find the func select monitor and click enable application insights.
How can I expand that script to enable automate this step for the newly created function? I have been unable to find any specific documentation or examples and I would prefer to avoid resource templates if possible.
OF course, you could enable Application Insights to the azure function by Azure CLI.
But you need to create the Application Insights in the portal first, currently, it is unable to create Application Insights via Azure CLI.
You could follow the steps below.
1.Go to your Application Insights in the portal, copy the Instrumentation Key in the screenshot.
2.After creating the function app by your command , just use the CLI command below.
az functionapp config appsettings set --name <functionname> --resource-group <resourcegroupname> --settings 'APPINSIGHTS_INSTRUMENTATIONKEY = <Instrumentation Key>'
It works fine on my side, you could check it in the portal.
Related
I have no experience in coding, just started now.
I am trying to create a webapp using the Azure Cloud Shell, so I used the following command:
az webapp create --name WebAppOne --resource-group learn-64c4ca17-0293-40f6-ba23-e4581751cca0 --plan ServicePlanTest
Then I get the message:
Webapp 'WebAppOne' already exists. The command will use the existing app's settings.
Unable to retrieve details of the existing app 'WebAppOne'. Please check that the app is a part of the current subscription
I only have one subscription in Azure as I am still using a free account for learning purposes.
So, I decided to get a list showing the webapps that exist by using the command:
az webapp list --output table
However, the only outcome is a blank line, showing no web apps already existing. What should I try next?
To create a web app in Azure App service, you must have a resource group and App service plan in your subscription.
To check the existing App services in your subscription
az webapp list --resource-group MyRGName
Output :
As you can see, currently I don't have any webapps created in the given Resource group
Run the below command to create an Azure Web App
az webapp create --name MyWebApp --resource-group MyRGName --plan MyAppServicePlan
Though I don't have any Webapps with the given name, I got the same error.
In Azure Portal => Azure Active Directory => App registrations => All applications
In search box, searched with the web app name. I can see the web app with same name is already created.
Reason for the error
You might have created a web app with same name long ago, but the resource got deleted from the resource group. But still, it is available in the Azure Active Directory App registrations.
If it is created by you and you don't want to use anymore, you can delete it. If not create web app with another name.
Tried to create web app with another name.
Create Azure App Service:
Now I can see the created Web App List.
List of Azure Web Apps
After running a DevOps pipeline that created several resources, only two (a new resource group and a Functions app) show up in Azure CLI using az ... list --subscription ....
Other resources, like Static Web Apps and a SQL Server don't show up in that list or when running az staticwebapp list --subscription ... or az sql server list --subscription ... with the subscription argument specified. I have confirmed that these resources DO show up in the portal, and my account is listed as an owner (inherited from subscription) for them in the portal.
I have deployed Azure Static WebApp using Azure Devops.
Followed this MSDoc to publish the static web app.
By using,
az staticwebapp list --resource-group YourRGName
and
az staticwebapp list --subscription YourSubscriptionID
,Iam able to get the StaticWeb App list
For anyone else running into this:
I have not found a solution to getting the az staticwebapp list command to work for my use case, as the results that show up immediately after creating a resource are just inconsistent. However, as a workaround that should satisfy most use cases, using this API (using az rest command) to find all resources associated with the group created by the pipeline, then filtering those down to find the Static Web App I want, seems to work.
Then, when using other APIs that reference that app before it shows up in the normal list, fully specifying subscription and resource group alongside the app's name seems to make things more reliable too.
As far as I can tell, this is probably just a limitation with the inconsistency of how long information about newly deployed resources takes to propagate that shows up when trying to find a resource immediately after creating it.
I'm facing an issue while deploying the azure function using Azure CLI or Azure PowerShell.
I have already created needed resources like resource group, function app and blob storage.
My function app platform type is Linux with consumption plan and runtime net6.0. I have created Service Bus trigger function and deployed using Visual Studio Publish profile and it is working as expected.
But when I executed the command to deploy the Azure function using CLI. Command is executing successfully but when I open the function app from azure portal and go to functions blade the deployed functions do not appear there.
I also checked the folder structure of the build output as mentioned in the link
https://learn.microsoft.com/en-us/azure/azure-functions/deployment-zip-push
any help would be appreciated.
Thanks
Reproduced the same issue from our end using Az-CLI
az functionapp deployment source config-zip -g <Resource Group> -n <Function App Name> --src <Function Project with Zip>
Workaround to fix the issue
After setting SCM_DO_BUILD_DURING_DEPLOYMENT to true in Configuration > Application Settings of the Azure Function App in Portal and deployed again using AZ CLI commands and shown the functions in Portal and in Kudu site of wwwroot folder.
AZ CLI Command:
az functionapp deployment source config-zip -g HariTestRG -n KrishNet6FuncApp --src "C:/Users/Hari/source/repos/DotNet6/TimerTrigger1205.zip"
According to this MS DOC, we came to know that some deployment customization has to be done before deploying the Function App as a Zip Push, i.e., by default the app setting SCM_DO_BUILD_DURING_DEPLOYMENT is false which enables the continuous integration deployment.
For the PowerShell Workaround, refer GitHub Page.
Function App running on Linux OS in consumption plan has limited deployment options but supports only remote build.
To enable remote build on Linux, the following application settings must be set:
ENABLE_ORYX_BUILD=true
SCM_DO_BUILD_DURING_DEPLOYMENT=true
If your project needs to use remote build, don't use the
WEBSITE_RUN_FROM_PACKAGE app setting.
Functions Core Tools is the only solution work for me.
By default, Azure Functions Core Tool perform remote builds when deploying to Linux. Because of this, it automatically create these settings for you in Azure.
func azure functionapp publish <FunctionAppName>
my custom script file
param(
[Parameter(Mandatory=$True)]
$AppName,
[Parameter(Mandatory=$True)]
$LocalProjectPath
)
cd "$($LocalProjectPath)"
func azure functionapp publish $AppName
cd ..
if you need more help with Linux hosting use this link Zip Deploymnet to get detailed information related to Azure Functions Deployments.
I haven't found a command line switch for enabling diagnostic settings when creating a VM with the Azure CLI.
I know it works in the portal, but likely this is a separate step in the deployment template.
However, there is a new command line switch for enabling log analytics workspace immediately (Preview).
az vm create cli does not provide the arguments about diagnostic settings, so I am afraid that we cannot enable diagnostic settings when creating an azure vm.
As workaround, you can try to enable the diagnostics settings using Azure CLI by following this document.
az vm diagnostics set --settings
[--ids]
[--no-auto-upgrade {false, true}]
[--protected-settings]
[--resource-group]
[--subscription]
[--version]
[--vm-name]
Here is a case on github you can refer to .
Is it possible to export the JSON definition for an existing app service in Azure?
Ie this json object: https://learn.microsoft.com/en-us/azure/templates/microsoft.web/sites
The app service was created using the Azure Portal UI and I want to recreate it using the Azure CLI command line.
You could use az group export --name *** >test.json to capture a resource group as a template. Please refer to this link.
But currently resource type Microsoft.Web/sites does not support export, please refer to this feedback.
Note: If also could find the error log on Azure Portal.